示例#1
0
 /**
  * Initialize model comments and return comment collection
  *
  * @return \Magento\Sales\Model\ResourceModel\Order\Comment\Collection\AbstractCollection
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getComments()
 {
     if ($this->_commentCollection === null) {
         $entity = $this->getEntity();
         if ($entity instanceof \Magento\Sales\Model\Order\Invoice) {
             $this->_commentCollection = $this->_invoiceCollectionFactory->create();
         } elseif ($entity instanceof \Magento\Sales\Model\Order\Creditmemo) {
             $this->_commentCollection = $this->_memoCollectionFactory->create();
         } elseif ($entity instanceof \Magento\Sales\Model\Order\Shipment) {
             $this->_commentCollection = $this->_shipmentCollectionFactory->create();
         } else {
             throw new \Magento\Framework\Exception\LocalizedException(__('We found an invalid entity model.'));
         }
         $this->_commentCollection->setParentFilter($entity)->setCreatedAtOrder()->addVisibleOnFrontFilter();
     }
     return $this->_commentCollection;
 }
示例#2
0
 /**
  * Returns comments
  *
  * @return \Magento\Sales\Api\Data\ShipmentCommentInterface[]
  */
 public function getComments()
 {
     if (!$this->getId()) {
         return $this->getData(ShipmentInterface::COMMENTS);
     }
     if ($this->getData(ShipmentInterface::COMMENTS) == null) {
         $collection = $this->_commentCollectionFactory->create()->setShipmentFilter($this->getId());
         foreach ($collection as $item) {
             $item->setShipment($this);
         }
         $this->setData(ShipmentInterface::COMMENTS, $collection->getItems());
     }
     return $this->getData(ShipmentInterface::COMMENTS);
 }
示例#3
0
 /**
  * Retrieve comments collection.
  *
  * @param bool $reload
  * @return \Magento\Sales\Model\ResourceModel\Order\Shipment\Comment\Collection
  */
 public function getCommentsCollection($reload = false)
 {
     if (!$this->hasData(ShipmentInterface::COMMENTS) || $reload) {
         $comments = $this->_commentCollectionFactory->create()->setShipmentFilter($this->getId())->setCreatedAtOrder();
         $this->setComments($comments);
         /**
          * When shipment created with adding comment,
          * comments collection must be loaded before we added this comment.
          */
         $this->getComments()->load();
         if ($this->getId()) {
             foreach ($this->getComments() as $comment) {
                 $comment->setShipment($this);
             }
         }
     }
     return $this->getComments();
 }
示例#4
0
 /**
  * Creates mock for comments collection factory
  * @return void
  */
 private function initCommentsCollectionFactoryMock()
 {
     $this->commentCollection = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->setMethods(['setShipmentFilter', 'setCreatedAtOrder', 'getItems', 'load', '__wakeup'])->getMock();
     $this->commentCollectionFactory = $this->getMockBuilder(CollectionFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->commentCollectionFactory->expects(static::any())->method('create')->willReturn($this->commentCollection);
 }