Esempio n. 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));
             }
         }
     }
 }
 /**
  * @param Template $templateContainer
  * @param InvoiceIdentity $identityContainer
  * @param Order\Email\SenderBuilderFactory $senderBuilderFactory
  * @param \Psr\Log\LoggerInterface $logger
  * @param PaymentHelper $paymentHelper
  * @param InvoiceResource $invoiceResource
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig
  * @param Renderer $addressRenderer
  * @param ManagerInterface $eventManager
  */
 public function __construct(Template $templateContainer, InvoiceIdentity $identityContainer, \Magento\Sales\Model\Order\Email\SenderBuilderFactory $senderBuilderFactory, \Psr\Log\LoggerInterface $logger, Renderer $addressRenderer, PaymentHelper $paymentHelper, InvoiceResource $invoiceResource, \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig, ManagerInterface $eventManager)
 {
     parent::__construct($templateContainer, $identityContainer, $senderBuilderFactory, $logger, $addressRenderer);
     $this->paymentHelper = $paymentHelper;
     $this->invoiceResource = $invoiceResource;
     $this->globalConfig = $globalConfig;
     $this->addressRenderer = $addressRenderer;
     $this->eventManager = $eventManager;
 }
 /**
  * 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;
 }
 /**
  * @param int $configValue
  * @param array|null $collectionItems
  * @param bool|null $emailSendingResult
  * @dataProvider executeDataProvider
  * @return void
  */
 public function testExecute($configValue, $collectionItems, $emailSendingResult)
 {
     $path = 'sales_email/general/async_sending';
     $this->globalConfig->expects($this->once())->method('getValue')->with($path)->willReturn($configValue);
     if ($configValue) {
         $this->entityCollection->expects($this->at(0))->method('addFieldToFilter')->with('send_email', ['eq' => 1]);
         $this->entityCollection->expects($this->at(1))->method('addFieldToFilter')->with('email_sent', ['null' => true]);
         $this->entityCollection->expects($this->any())->method('getItems')->willReturn($collectionItems);
         if ($collectionItems) {
             /** @var \Magento\Sales\Model\AbstractModel|\PHPUnit_Framework_MockObject_MockObject $collectionItem */
             $collectionItem = $collectionItems[0];
             $this->emailSender->expects($this->once())->method('send')->with($collectionItem, true)->willReturn($emailSendingResult);
             if ($emailSendingResult) {
                 $collectionItem->expects($this->once())->method('setEmailSent')->with(true)->willReturn($collectionItem);
                 $this->entityResource->expects($this->once())->method('save')->with($collectionItem);
             }
         }
     }
     $this->object->sendEmails();
 }
Esempio n. 5
0
 /**
  * Prepare email template with variables
  *
  * @param Order $order
  * @return void
  */
 protected function prepareTemplate(Order $order)
 {
     $transport = new \Magento\Framework\Object(['template_vars' => ['order' => $order, 'billing' => $order->getBillingAddress(), 'payment_html' => $this->getPaymentHtml($order), 'store' => $order->getStore(), 'formattedShippingAddress' => $this->addressRenderer->format($order->getShippingAddress(), 'html'), 'formattedBillingAddress' => $this->addressRenderer->format($order->getBillingAddress(), 'html')]]);
     $this->eventManager->dispatch('email_order_set_template_vars_before', ['sender' => $this, 'transport' => $transport]);
     $this->templateContainer->setTemplateVars($transport->getTemplateVars());
     parent::prepareTemplate($order);
 }
Esempio n. 6
0
 /**
  * Prepare email template with variables
  *
  * @param Order $order
  * @return void
  */
 protected function prepareTemplate(Order $order)
 {
     $transport = ['order' => $order, 'billing' => $order->getBillingAddress(), 'payment_html' => $this->getPaymentHtml($order), 'store' => $order->getStore(), 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order)];
     $this->eventManager->dispatch('email_order_set_template_vars_before', ['sender' => $this, 'transport' => $transport]);
     $this->templateContainer->setTemplateVars($transport);
     parent::prepareTemplate($order);
 }
Esempio n. 7
0
 /**
  * Prepare email template with variables
  *
  * @param Order $order
  * @return void
  */
 protected function prepareTemplate(Order $order)
 {
     $this->templateContainer->setTemplateVars(['order' => $order, 'billing' => $order->getBillingAddress(), 'payment_html' => $this->getPaymentHtml($order), 'store' => $order->getStore()]);
     parent::prepareTemplate($order);
 }