我尝试在 Mage/Catalog/Block/Product/List.php, _getProductCollection() 上添加以下内容
$this->_productCollection
->addAttributeToFilter('category_id', array('nin' => array('36,37'),));
但它想出了:
Fatal error: Call to a member function getBackend() on a non-object in C:\app\code\core\Mage\Eav\Model\Entity\Abstract.php on line 816
我怀疑这是因为它正在寻找产品没有“category_id”的属性,我尝试添加:
$this->_productCollection
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
->addAttributeToFilter('category_id', array('nin' => array('36,37'),));
但这带来了另一个错误:
Joined field with this alias is already declared"
我究竟做错了什么?
Mage/Catalog/Block/Product/List.php 是应用此覆盖的正确文件吗?
我只是希望它适用于搜索结果,即 catalogsearch/result/