Reputation: 4111
In my magento store (ce-1.9.0) I have setup a custom product attribute:
custom_depth_check
And the attribute has the setting of
Used in Product Listing : Yes
Used for Sorting in Product Listing : Yes
I now need to filter any getLoadedProductCollection()
with this attribute. The attribute will either be set at:
null
0
1
I need to filter all instances of getLoadedProductCollection()
so that it will EXLCUDE any products with
custom_depth_check : 1
I have tried to clear and reload like so:
$_productCollection=$this->getLoadedProductCollection()
->clear()
->addAttributeToFilter('custom_depth_check', array('neq' => 1));
But that results in an empty collection. I also tried adding ->load()
at the end but again nothing comes up.
Upvotes: 1
Views: 5956
Reputation: 219
The collection is loaded in the file: app/code/Mage/Catalog/Block/Product/List.php in the function: _getProductCollection()
Do a local ovveride by copyng that file in local folder app/code/local/Mage/Catalog/Block/Product/List.php
and add your new filters just before the line
$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
your code will be like:
$this->_productCollection->addAttributeToFilter('custom_depth_check', array('neq' => 1)); //Your new filter
$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
best regards Giuseppe
Upvotes: 2