I am trying to set up an attribute for EOL (end of life) products. The idea is to leave these products on site, but now buying option would be available for them, and also they shouldn't appear on category listing pages and in the datafeeds.

I set up a boolean attribute for this and already did the product page, but I can't figure out how to filter out these products from the category listing. In list.phtml I see that the $_productCollection already contains all products, how can I filter out the products with the eol attribute set to yes?

2 Answers 2


To filter collection:

$your_collection->addAttributeToFilter('your_attribute_code', array('eq' => true));

To filter product on phtml:

if($product->getData('your_attribute_code')) { // If it returns boolean
  • Filtering the collection somehow disabled the entire layered navigation block, filtering on phtml works, however the total count isn't changed, because it only shows the products that have the attribute value set to "No". I tried to decrease the $_productCollection every time it finds a product with the attribute set to yes, but I guess the total number of the products is returned before the products are displayed. Here is the page: bricomix.ro/it-c/telefoane-mobile.html As you can see there are only 4 products displayed, yet on the left side, next to the HTC we have a number 5.
    – Andras
    Jan 24, 2015 at 11:36
  • Different blocks may use different collections. You should track them out and extend those blocks to filter their collections too. Besides, you should modify your attribute's options as Show on frontend and etc. See them in Admin panel -> Catalog -> Attributes -> Manage attributes. I don't know full logic of your site, but from my point of view the attribute is excessive here. If you get this attribute from somewhere, it would be easier just to update products' status once in import script than create calls to database for each product.
    – Amberta
    Jan 27, 2015 at 9:46

Inside for loop wrap your html which displays product with below, please ignore syntax

if ($_getattribute('yourattribute name') == true ) 
//your html to add prdouctss...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.