0

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

任何人都可以帮忙吗?

问候!

4

2 回答 2

3

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

将/app/code/core/Mage/Review/Block/Product/View.php从core复制到本地,并修改。第 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();
}
于 2014-07-09T21:53:27.013 回答
0

首先使用以下语句获取属于 Configurable 产品的产品的 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。

于 2012-07-03T04:24:00.947 回答