我想在可配置产品的页面上显示简单产品的评论。
有人能帮上忙吗?
致以问候!
发布于 2014-07-10 05:53:27
下面的代码将显示可配置产品和简单产品的评分和评论。请注意,您还应该修改产品页面顶部的摘要,该摘要显示审查计数和总体平均评分。
将/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();
}发布于 2012-07-03 12:24:01
首先,使用以下语句获取属于可配置产品的产品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。
https://stackoverflow.com/questions/11287964
复制相似问题