我正在撰寫一個模塊,爲我加載特色產品列表。所有特色產品都坐在自己的類別+隱藏類別「特色」。該腳本返回一個錯誤。Magento:按兩種類別篩選產品集合
在分類視圖(list.phtml)我呼籲gettopproducts.phtml
(工作正常):
<?php $currentCategory = Mage::registry('current_category'); ?>
<?php $_products = $this->getTopProducts($currentCategory); ?>
<?php echo $this->__('Available products: ').$_products->count(); ?>
從gettopproducts.phtml
我調用一個函數的Gettopproducts.php
getTopProducts()
使電流類別。在Gettopproducts.php
我有這樣的:
public function getTopProducts($currentCategory)
{
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addCategoryFilter($currentCategory)
->addAttributeToFilter('category_ids',array('finset'=>'87'));
$_productCollection->load();
return $_productCollection;
}
該行:->addAttributeToFilter('category_ids',array('finset'=>'87'));
應該添加第二個類別過濾器(以下簡稱「特色」類別的ID)。但是,當我使用這個,我得到一個錯誤。當我刪除這一行:->addAttributeToFilter('category_ids',array('finset'=>'87'));
它完美的作品。
我使用的Magento 1.7.2