Skip to content

Commit

Permalink
Merge pull request #18 from ThomasDaSilva/master
Browse files Browse the repository at this point in the history
Revert event to TheliaEvents::ORDER_UPDATE_STATUS
  • Loading branch information
julescournut committed Dec 20, 2022
2 parents 6c6013e + 6f8d371 commit d5f1acb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.2.10</version>
<version>1.2.11</version>
<author>
<name>Julien Chanséaume</name>
<email>julien@thelia.net</email>
Expand Down
15 changes: 11 additions & 4 deletions EventListeners/StockAlertManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
use StockAlert\StockAlert;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\Newsletter\NewsletterEvent;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\ProductSaleElement\ProductSaleElementUpdateEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Log\Tlog;
use Thelia\Mailer\MailerFactory;
use Thelia\Model\ConfigQuery;
use Thelia\Model\Event\ProductSaleElementsEvent;
use Thelia\Model\Lang;
use Thelia\Model\NewsletterQuery;
use Thelia\Model\ProductQuery;
Expand Down Expand Up @@ -60,7 +60,7 @@ public static function getSubscribedEvents()
return [
StockAlertEvents::STOCK_ALERT_SUBSCRIBE => ['subscribe', 128],
TheliaEvents::PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT => ['checkStock', 120],
ProductSaleElementsEvent::POST_SAVE => ['checkStockForAdmin', 128],
TheliaEvents::ORDER_UPDATE_STATUS => ['checkStockForAdmin', 128],
];
}

Expand Down Expand Up @@ -182,11 +182,18 @@ public function sendEmail(RestockingAlert $subscriber)
}
}

public function checkStockForAdmin(ProductSaleElementsEvent $event)
public function checkStockForAdmin(OrderEvent $event)
{
$pseIds = $event->getModel()->getId();
$order = $event->getOrder();

$config = StockAlert::getConfig();

$pseIds = [];

foreach ($order->getOrderProducts() as $orderProduct) {
$pseIds[] = $orderProduct->getProductSaleElementsId();
}

if ($config['enabled']) {
$threshold = $config['threshold'];

Expand Down
20 changes: 20 additions & 0 deletions Model/StockProductAlert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace StockAlert\Model;

use StockAlert\Model\Base\StockProductAlert as BaseStockProductAlert;

/**
* Skeleton subclass for representing a row from the 'stock_product_alert' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class StockProductAlert extends BaseStockProductAlert
{

}
20 changes: 20 additions & 0 deletions Model/StockProductAlertQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace StockAlert\Model;

use StockAlert\Model\Base\StockProductAlertQuery as BaseStockProductAlertQuery;

/**
* Skeleton subclass for performing query and update operations on the 'stock_product_alert' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class StockProductAlertQuery extends BaseStockProductAlertQuery
{

}

0 comments on commit d5f1acb

Please sign in to comment.