diff --git a/Command/SendMailStockPse.php b/Command/SendMailStockPse.php
new file mode 100644
index 0000000..b0d0ba8
--- /dev/null
+++ b/Command/SendMailStockPse.php
@@ -0,0 +1,37 @@
+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é");
+ }
+}
\ No newline at end of file
diff --git a/Config/config.xml b/Config/config.xml
index 7f09fbc..00e474f 100644
--- a/Config/config.xml
+++ b/Config/config.xml
@@ -13,11 +13,18 @@
+
+
+
+
+
+
+
diff --git a/Config/module.xml b/Config/module.xml
index 6bf76e0..5d83176 100644
--- a/Config/module.xml
+++ b/Config/module.xml
@@ -13,7 +13,7 @@
en_US
fr_FR
- 1.2.8
+ 1.2.9
Julien Chanséaume
julien@thelia.net
diff --git a/Config/schema.xml b/Config/schema.xml
index ce98ed7..df521a4 100644
--- a/Config/schema.xml
+++ b/Config/schema.xml
@@ -17,6 +17,19 @@
+
+
diff --git a/Config/sqldb.map b/Config/sqldb.map
new file mode 100644
index 0000000..63a93ba
--- /dev/null
+++ b/Config/sqldb.map
@@ -0,0 +1,2 @@
+# Sqlfile -> Database map
+thelia.sql=thelia
diff --git a/Config/thelia.sql b/Config/thelia.sql
index 975ff98..8b9decf 100644
--- a/Config/thelia.sql
+++ b/Config/thelia.sql
@@ -18,12 +18,32 @@ CREATE TABLE `restocking_alert`
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`),
- INDEX `FI_restocking_alert_product_sale_elements_id` (`product_sale_elements_id`),
+ INDEX `fi_restocking_alert_product_sale_elements_id` (`product_sale_elements_id`),
CONSTRAINT `fk_restocking_alert_product_sale_elements_id`
FOREIGN KEY (`product_sale_elements_id`)
REFERENCES `product_sale_elements` (`id`)
ON DELETE CASCADE
) ENGINE=InnoDB;
+-- ---------------------------------------------------------------------
+-- stock_product_alert
+-- ---------------------------------------------------------------------
+
+DROP TABLE IF EXISTS `stock_product_alert`;
+
+CREATE TABLE `stock_product_alert`
+(
+ `id` INTEGER NOT NULL AUTO_INCREMENT,
+ `product_id` INTEGER NOT NULL,
+ `created_at` DATETIME,
+ `updated_at` DATETIME,
+ PRIMARY KEY (`id`),
+ INDEX `fi_stock_pse_alert_product_id` (`product_id`),
+ CONSTRAINT `fk_stock_pse_alert_product_id`
+ FOREIGN KEY (`product_id`)
+ REFERENCES `product` (`id`)
+ ON DELETE CASCADE
+) ENGINE=InnoDB;
+
# This restores the fkey checks, after having unset them earlier
SET FOREIGN_KEY_CHECKS = 1;
diff --git a/EventListeners/StockAlertManager.php b/EventListeners/StockAlertManager.php
index 187e4c7..2ad28c6 100644
--- a/EventListeners/StockAlertManager.php
+++ b/EventListeners/StockAlertManager.php
@@ -18,6 +18,8 @@
use StockAlert\Event\StockAlertEvents;
use StockAlert\Model\RestockingAlert;
use StockAlert\Model\RestockingAlertQuery;
+use StockAlert\Model\StockProductAlert;
+use StockAlert\Model\StockProductAlertQuery;
use StockAlert\StockAlert;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\Newsletter\NewsletterEvent;
@@ -93,7 +95,7 @@ public function subscribe(StockAlertEvent $event)
}
if ($subscribeToNewsLetter) {
- $this->subscribeNewsletter($email,$event);
+ $this->subscribeNewsletter($email, $event);
}
@@ -106,7 +108,7 @@ protected function subscribeNewsletter($email, StockAlertEvent $event)
if (!$customer) {
- $newsletter = new NewsletterEvent($email,"fr_FR");
+ $newsletter = new NewsletterEvent($email, "fr_FR");
$event->getDispatcher()->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $newsletter);
}
@@ -161,8 +163,8 @@ public function sendEmail(RestockingAlert $subscriber)
$this->mailer->sendEmailMessage(
'stockalert_customer',
- [ $contactEmail => ConfigQuery::read('store_name') ],
- [ $subscriber->getEmail() => ConfigQuery::read('store_name') ],
+ [$contactEmail => ConfigQuery::read('store_name')],
+ [$subscriber->getEmail() => ConfigQuery::read('store_name')],
[
'locale' => $subscriber->getLocale(),
'pse_id' => $pse->getId(),
@@ -183,7 +185,6 @@ public function sendEmail(RestockingAlert $subscriber)
public function checkStockForAdmin(ProductSaleElementsEvent $event)
{
$pseIds = $event->getModel()->getId();
-
$config = StockAlert::getConfig();
if ($config['enabled']) {
@@ -201,40 +202,15 @@ public function checkStockForAdmin(ProductSaleElementsEvent $event)
->toArray();
if (!empty($productIds)) {
- $this->sendEmailForAdmin($config['emails'], $productIds);
- }
- }
- }
-
- public function sendEmailForAdmin($emails, $productIds)
- {
- $locale = Lang::getDefaultLanguage()->getLocale();
-
- $contactEmail = ConfigQuery::read('store_email');
-
- if ($contactEmail) {
- $storeName = ConfigQuery::read('store_name');
+ foreach ($productIds as $productId) {
- $to = [];
-
- foreach ($emails as $recipient) {
- $to[$recipient] = $storeName;
+ if (!StockProductAlertQuery::create()->findOneByProductId($productId)){
+ $stockPseAlert = new StockProductAlert();
+ $stockPseAlert->setProductId($productId);
+ $stockPseAlert->save();
+ }
+ }
}
-
- $this->mailer->sendEmailMessage(
- 'stockalert_administrator',
- [ $contactEmail => $storeName ],
- $to,
- [
- 'locale' => $locale,
- 'products_id' => $productIds
- ],
- $locale
- );
-
- Tlog::getInstance()->debug("Stock Alert sent to administrator " . implode(', ', $emails));
- } else {
- Tlog::getInstance()->debug("Restocking Alert: no contact email is defined !");
}
}
}
diff --git a/Service/adminMailService.php b/Service/adminMailService.php
new file mode 100644
index 0000000..455951b
--- /dev/null
+++ b/Service/adminMailService.php
@@ -0,0 +1,53 @@
+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 !");
+ }
+ }
+}
\ No newline at end of file