Beispiel #1
0
 /**
  * Handles asynchronous email sending during corresponding
  * cron job.
  *
  * Also method is used in the next events:
  *
  * - config_data_sales_email_general_async_sending_disabled
  *
  * Works only if asynchronous email sending is enabled
  * in global settings.
  *
  * @return void
  */
 public function execute()
 {
     if ($this->globalConfig->getValue('sales_email/general/async_sending')) {
         $this->entityCollection->addFieldToFilter('send_email', ['eq' => 1]);
         $this->entityCollection->addFieldToFilter('email_sent', ['null' => true]);
         /** @var \Magento\Sales\Model\AbstractModel $item */
         foreach ($this->entityCollection->getItems() as $item) {
             if ($this->emailSender->send($item, true)) {
                 $this->entityResource->save($item->setEmailSent(true));
             }
         }
     }
 }
 /**
  * Notify user
  *
  * @param AbstractModel $model
  * @return bool
  * @throws \Magento\Framework\Exception\MailException
  */
 public function notify(\Magento\Sales\Model\AbstractModel $model)
 {
     try {
         $this->sender->send($model);
         if (!$model->getEmailSent()) {
             return false;
         }
         $historyItem = $this->historyCollectionFactory->create()->getUnnotifiedForInstance($model);
         if ($historyItem) {
             $historyItem->setIsCustomerNotified(1);
             $historyItem->save();
         }
     } catch (\Magento\Framework\Exception\MailException $e) {
         $this->logger->critical($e);
         return false;
     }
     return true;
 }