-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from ThomasDaSilva/master
change stock admin alert
- Loading branch information
Showing
8 changed files
with
147 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace StockAlert\Command; | ||
|
||
use StockAlert\Model\StockProductAlertQuery; | ||
use StockAlert\Service\adminMailService; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Thelia\Command\ContainerAwareCommand; | ||
|
||
class SendMailStockPse extends ContainerAwareCommand | ||
{ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName("stockalert:adminMail") | ||
->setDescription("send mail with all products with no stock"); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->initRequest(); | ||
$productIds = StockProductAlertQuery::create() | ||
->select('product_id') | ||
->find(); | ||
|
||
/** @var adminMailService $adminMailService */ | ||
$adminMailService = $this->getContainer()->get('stockalert.alert.service'); | ||
|
||
$adminMailService->sendEmailForAdmin($productIds); | ||
$output->writeln("StockAlert : Mail envoyé"); | ||
|
||
StockProductAlertQuery::create() | ||
->deleteAll(); | ||
$output->writeln("StockAlert : Table vidé"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Sqlfile -> Database map | ||
thelia.sql=thelia |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace StockAlert\Service; | ||
|
||
use StockAlert\StockAlert; | ||
use Thelia\Log\Tlog; | ||
use Thelia\Mailer\MailerFactory; | ||
use Thelia\Model\ConfigQuery; | ||
use Thelia\Model\Lang; | ||
|
||
class adminMailService | ||
{ | ||
protected $mailer; | ||
|
||
public function __construct(MailerFactory $mailer) | ||
{ | ||
$this->mailer = $mailer; | ||
} | ||
|
||
public function sendEmailForAdmin($productIds) | ||
{ | ||
$locale = Lang::getDefaultLanguage()->getLocale(); | ||
|
||
$config = StockAlert::getConfig(); | ||
|
||
$contactEmail = ConfigQuery::read('store_email'); | ||
|
||
if ($contactEmail) { | ||
$storeName = ConfigQuery::read('store_name'); | ||
|
||
$to = []; | ||
|
||
foreach ($config['emails'] as $recipient) { | ||
$to[$recipient] = $storeName; | ||
} | ||
|
||
$this->mailer->sendEmailMessage( | ||
'stockalert_administrator', | ||
[$contactEmail => $storeName], | ||
$to, | ||
[ | ||
'locale' => $locale, | ||
'products_id' => $productIds | ||
], | ||
$locale | ||
); | ||
|
||
Tlog::getInstance()->debug("Stock Alert sent to administrator " . implode(', ', $config['emails'])); | ||
} else { | ||
Tlog::getInstance()->debug("Restocking Alert: no contact email is defined !"); | ||
} | ||
} | ||
} |