Magento - 在可配置产品页面上显示简单的产品评论

时间:2012-07-02 04:57:04

标签: php magento

我想在可配置产品的页面上显示简单产品的评论。

有人可以帮忙吗?

问候!

2 个答案:

答案 0 :(得分:3)

以下代码将显示可配置和简单产品的评级和评论。请注意,您还应修改产品页面顶部的摘要,其中显示了评论计数和&总体平均评级。

将/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();
}

答案 1 :(得分: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。