Example #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));
             }
         }
     }
 }
Example #2
0
 /**
  * @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->execute();
 }
Example #3
0
 /**
  * Reset left join
  *
  * @param int $limit
  * @param int $offset
  * @return \Magento\Eav\Model\Entity\Collection\AbstractCollection
  */
 protected function _getAllIdsSelect($limit = null, $offset = null)
 {
     $idsSelect = parent::_getAllIdsSelect($limit, $offset);
     $idsSelect->resetJoinLeft();
     return $idsSelect;
 }