public function checkStock(ProductSaleElementUpdateEvent $productSaleElementUpdateEvent) { if ($productSaleElementUpdateEvent->getQuantity() > 0) { // add extra checking $pse = ProductSaleElementsQuery::create()->findPk($productSaleElementUpdateEvent->getProductSaleElementId()); $availabilityEvent = new ProductSaleElementAvailabilityEvent($pse); $productSaleElementUpdateEvent->getDispatcher()->dispatch(StockAlertEvents::STOCK_ALERT_CHECK_AVAILABILITY, $availabilityEvent); if ($availabilityEvent->isAvailable()) { $subscribers = RestockingAlertQuery::create()->filterByProductSaleElementsId($productSaleElementUpdateEvent->getProductSaleElementId())->find(); if (null !== $subscribers) { foreach ($subscribers as $subscriber) { try { $this->sendEmail($subscriber); $subscriber->delete(); } catch (\Exception $ex) { } } } } } }