Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractNotifier.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Sales\Model;
8 
9 use Psr\Log\LoggerInterface as Logger;
11 use Magento\Sales\Model\ResourceModel\Order\Status\History\CollectionFactory;
12 
18 {
23 
27  protected $logger;
28 
32  protected $sender;
33 
39  public function __construct(
40  CollectionFactory $historyCollectionFactory,
41  Logger $logger,
43  ) {
44  $this->historyCollectionFactory = $historyCollectionFactory;
45  $this->logger = $logger;
46  $this->sender = $sender;
47  }
48 
56  public function notify(\Magento\Sales\Model\AbstractModel $model)
57  {
58  try {
59  $this->sender->send($model);
60  if (!$model->getEmailSent()) {
61  return false;
62  }
63  $historyItem = $this->historyCollectionFactory->create()
64  ->getUnnotifiedForInstance($model);
65  if ($historyItem) {
66  $historyItem->setIsCustomerNotified(1);
67  $historyItem->save();
68  }
69  } catch (\Magento\Framework\Exception\MailException $e) {
70  $this->logger->critical($e);
71  return false;
72  }
73  return true;
74  }
75 }
notify(\Magento\Sales\Model\AbstractModel $model)
__construct(CollectionFactory $historyCollectionFactory, Logger $logger, Sender $sender)