2012-07-02 146 views

回答

0

首先屬於配置的產品,這種說法的產品都得到ID的:

$children_ids = Mage::getModel ('catalog/product_type_configurable')->getChildrenIds ($_product->getId()); 

通過各種簡單的產品,然後遍歷,並得到他們的評論,這樣的:

foreach ($children_ids as $child_id) 
    { 
     foreach ($child_id as $id) 
     { 
      $_items2 = Mage::getModel('review/review')->getCollection() 
         ->addStoreFilter(Mage::app()->getStore()->getId()) 
         ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED) 
         ->addEntityFilter('product', $id) 
         ->addRateVotes() 
         ->setDateOrder(); 
      $_items = $_items2->getItems(); 
}} 

查看「view/list.phtml」瞭解如何使用$ _items。

2

下面的代碼將顯示可配置產品和簡單產品的評分和評論。請注意,您還應修改產品頁面頂部的摘要,以顯示審覈計數&的總體平均評分。

從核心複製/app/code/core/Mage/Review/Block/Product/View.php到本地,並對其進行修改。 線75是:

$this->_reviewsCollection = Mage::getModel('review/review')->getCollection() 
->addStoreFilter(Mage::app()->getStore()->getId()) 
->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED) 
->addEntityFilter('product', $this->getProduct()->getId()) 
->setDateOrder(); 

將其更改爲:

if ($this->getProduct()->isConfigurable()){ 
    //Get both configurable product and associated simple product reviews 
    $children_ids = Mage::getModel('catalog/product_type_configurable')->getChildrenIds($this->getProduct()->getId()); 
    $entity_ids = array($this->getProduct()->getId(), $children_ids); 

    $this->_reviewsCollection = Mage::getModel('review/review')->getCollection() 
     ->addStoreFilter(Mage::app()->getStore()->getId()) 
     ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED) 
     ->addFieldToFilter('entity_pk_value', array('in' => $entity_ids)) 
     ->setDateOrder(); 
} else { 
    $this->_reviewsCollection = Mage::getModel('review/review')->getCollection() 
    ->addStoreFilter(Mage::app()->getStore()->getId()) 
    ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED) 
    ->addEntityFilter('product', $this->getProduct()->getId()) 
    ->setDateOrder(); 
} 
+0

有許多 「本地」 文件夾在Magento文件樹中。哪個應該放置View.php?我嘗試了app/code/local/View.php和app/code/local/Review/Block/Product/View.php,以及app/code/local/Mage/Review/Block/Product/View.php – Dwayne

相關問題