Magento - 添加过滤器到 getLoadedProductCollection()

Magento - Add filter to getLoadedProductCollection()

在我的 magento 商店 (ce-1.9.0) 中,我设置了一个自定义产品属性:

custom_depth_check

并且属性设置为

Used in Product Listing : Yes
Used for Sorting in Product Listing : Yes

我现在需要使用此属性过滤任何 getLoadedProductCollection()。该属性将设置为:

null
0
1

我需要过滤 getLoadedProductCollection() 的所有实例,以便它会排除任何带有

的产品
custom_depth_check : 1

我试过像这样清除和重新加载:

$_productCollection=$this->getLoadedProductCollection()
->clear()
->addAttributeToFilter('custom_depth_check', array('neq' => 1));

但这会导致集合为空。我也尝试在最后添加 ->load() 但还是没有出现。

集合加载到文件中: app/code/Mage/Catalog/Block/Product/List.php 在函数中: _getProductCollection()

通过复制本地文件夹中的文件来进行本地 ovveride app/code/local/Mage/Catalog/Block/Product/List.php

并在

行之前添加您的新过滤器
$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());

您的代码如下:

$this->_productCollection->addAttributeToFilter('custom_depth_check', array('neq' => 1)); //Your new filter
$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());      

此致 朱塞佩