Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * Run test getStatusHistories method
  *
  * @return void
  */
 public function testGetStatusHistories()
 {
     $itemMock = $this->getMockForAbstractClass('Magento\\Sales\\Api\\Data\\OrderStatusHistoryInterface', [], '', false, true, true, ['setOrder']);
     $dbMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db', ['setOrder'], [], '', false);
     $collectionMock = $this->getMock('Magento\\Sales\\Model\\Resource\\Order\\Status\\History\\Collection', ['setOrderFilter', 'setOrder', 'getItems', 'getIterator', 'toOptionArray', 'count', 'load'], [], '', false);
     $collectionItems = [$itemMock];
     $collectionMock->expects($this->once())->method('setOrderFilter')->with($this->order)->willReturnSelf();
     $collectionMock->expects($this->once())->method('setOrder')->with('created_at', 'desc')->willReturn($dbMock);
     $dbMock->expects($this->once())->method('setOrder')->with('entity_id', 'desc')->willReturn($collectionMock);
     $collectionMock->expects($this->once())->method('getItems')->willReturn($collectionItems);
     $this->historyCollectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock);
     for ($i = 10; --$i;) {
         $this->assertEquals($collectionItems, $this->order->getStatusHistories());
     }
 }