/** * Initialize model comments and return comment collection * * @return \Magento\Sales\Model\Resource\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; }
/** * @param bool $reload * @return \Magento\Sales\Model\Resource\Order\Creditmemo\Comment\Collection */ public function getCommentsCollection($reload = false) { if (is_null($this->_comments) || $reload) { $this->_comments = $this->_commentCollectionFactory->create()->setCreditmemoFilter($this->getId())->setCreatedAtOrder(); /** * When credit memo created with adding comment, * comments collection must be loaded before we added this comment. */ $this->_comments->load(); if ($this->getId()) { foreach ($this->_comments as $comment) { $comment->setCreditmemo($this); } } } return $this->_comments; }
/** * @param bool $reload * @return \Magento\Sales\Model\Resource\Order\Creditmemo\Comment\Collection * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function getCommentsCollection($reload = false) { $collection = $this->_commentCollectionFactory->create()->setCreditmemoFilter($this->getId())->setCreatedAtOrder(); // // $this->setComments($comments); // /** // * When credit memo created with adding comment, // * comments collection must be loaded before we added this comment. // */ // $this->getComments()->load(); if ($this->getId()) { foreach ($collection as $comment) { $comment->setCreditmemo($this); } } return $collection; }