获取按类别过滤的产品评论
Get product reviews filtered by category
如何按类别过滤产品评论?
我有一个类别,如果我在一个产品中添加评论并且我想在该类别的所有产品中显示该评论。
我得到答案覆盖这个class"Mage_Review_Block_Product_View"
class Example_Block_Product_View extends Mage_Review_Block_Product_View {
public function getReviewsCollection() {
$category_id = Mage::registry ( 'current_category' )->getId ();
$category = Mage::getModel ( 'catalog/category' )->load ( $category_id );
$productCollection = Mage::getModel ( 'catalog/product' )
->getCollection ()
->addAttributeToSelect ( '*' )
->addCategoryFilter ( $category )
->load ();
foreach ( $productCollection as $product ) {
$product_ids [] = $product->getId ();
}
if (null === $this->_reviewsCollection) {
$this->_reviewsCollection = Mage::getModel ( 'review/review' )
->getCollection ()
->addStoreFilter ( Mage::app ()->getStore ()->getId () )
->addStatusFilter ( Mage_Review_Model_Review::STATUS_APPROVED )
->addFieldToFilter ( 'entity_id', Mage_Review_Model_Review::ENTITY_PRODUCT )
->addFieldToFilter ( 'entity_pk_value', array (
'in' => $product_ids
) )->setDateOrder ();
}
return $this->_reviewsCollection;
}
}
如何按类别过滤产品评论?
我有一个类别,如果我在一个产品中添加评论并且我想在该类别的所有产品中显示该评论。
我得到答案覆盖这个class"Mage_Review_Block_Product_View"
class Example_Block_Product_View extends Mage_Review_Block_Product_View {
public function getReviewsCollection() {
$category_id = Mage::registry ( 'current_category' )->getId ();
$category = Mage::getModel ( 'catalog/category' )->load ( $category_id );
$productCollection = Mage::getModel ( 'catalog/product' )
->getCollection ()
->addAttributeToSelect ( '*' )
->addCategoryFilter ( $category )
->load ();
foreach ( $productCollection as $product ) {
$product_ids [] = $product->getId ();
}
if (null === $this->_reviewsCollection) {
$this->_reviewsCollection = Mage::getModel ( 'review/review' )
->getCollection ()
->addStoreFilter ( Mage::app ()->getStore ()->getId () )
->addStatusFilter ( Mage_Review_Model_Review::STATUS_APPROVED )
->addFieldToFilter ( 'entity_id', Mage_Review_Model_Review::ENTITY_PRODUCT )
->addFieldToFilter ( 'entity_pk_value', array (
'in' => $product_ids
) )->setDateOrder ();
}
return $this->_reviewsCollection;
}
}