/** * 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; }
/** * Run test getStatusHistories method * * @return void */ public function testGetStatusHistories() { $itemMock = $this->getMockForAbstractClass( 'Magento\Sales\Api\Data\OrderStatusHistoryInterface', [], '', false, true, true, ['setOrder'] ); $dbMock = $this->getMockBuilder('Magento\Framework\Data\Collection\AbstractDb') ->setMethods(['setOrder']) ->disableOriginalConstructor() ->getMockForAbstractClass(); $collectionMock = $this->getMock( 'Magento\Sales\Model\ResourceModel\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()); } }
/** * Return collection of order status history items. * * @return HistoryCollection */ public function getStatusHistoryCollection() { $collection = $this->_historyCollectionFactory->create()->setOrderFilter($this) ->setOrder('created_at', 'desc') ->setOrder('entity_id', 'desc'); if ($this->getId()) { foreach ($collection as $status) { $status->setOrder($this); } } return $collection; }