_entity = $entity; $this->_commentCollection = null; // Changing model and resource model can lead to change of comment collection return $this; } /** * Gets comments parent model instance * * @return Mage_Sales_Model_Abstract */ public function getEntity() { return $this->_entity; } /** * Initialize model comments and return comment collection * * @return Mage_Sales_Model_Mysql4_Order_Comment_Collection_Abstract */ public function getComments() { if (is_null($this->_commentCollection)) { $entity = $this->getEntity(); if ($entity instanceof Mage_Sales_Model_Order_Invoice) { $collectionClass = 'sales/order_invoice_comment_collection'; } else if ($entity instanceof Mage_Sales_Model_Order_Creditmemo) { $collectionClass = 'sales/order_creditmemo_comment_collection'; } else if ($entity instanceof Mage_Sales_Model_Order_Shipment) { $collectionClass = 'sales/order_shipment_comment_collection'; } else { Mage::throwException(Mage::helper('sales')->__('Invalid entity model')); } $this->_commentCollection = Mage::getResourceModel($collectionClass); $this->_commentCollection->setParentFilter($entity) ->setCreatedAtOrder() ->addVisibleOnFrontFilter(); } return $this->_commentCollection; } /** * Returns whether there are comments to show on frontend * * @return bool */ public function hasComments() { return $this->getComments()->count() > 0; } }