I want to select ids of a specific brand when I have the name and the Id of a product for example 111

I found out the ID of manufacturer by using getManufacturer()

I used this code in template/catalog/product/list.phtml :

$_collection_selected=$_productCollection->addAttributeToFilter('manufacturer', array('eq' => 111));
    foreach ($_collection_selected as $_product_selected):

but it shows me all the products I don't know what is wrong?


1 Answer 1


Your problem probably lies in the fact that the collection you try to adjust is already loaded. When a collection is loaded, the query is already executed and the data is ready for usage in the collection.

The only way to adjust the collection after loading is by calling a $collection->clear(). If you want mor detailed technical information you can check the Mage_Catalog_Model_Resource_Product_Collection in which the clear() method can be found.

  • I didn't write $this->getLoadedProductCollection() it was there before and it doesn't have problem and I don't change it so no need to call it
    – Nickool
    Feb 28, 2014 at 21:30
  • Yes, correct. The call was already there and you did not made a change it. But afterwards, the 2nd line in your snippet, you try to append a attribute filter to that very collection. This new attribute filter will be ignored by Magento, since the collection you try to adjust is already in a 'loaded' state. Hence the result is still all the products. You can only apply attribute filters before the collection is loaded. Hence the loaded state must be cleared as I tried to explain in my answer.
    – Tim Hofman
    Feb 28, 2014 at 21:38
  • you don't know how much I should thank you! brilliant!
    – Nickool
    Feb 28, 2014 at 21:48
  • Sounds like you made some progress :). Good luck with the rest!
    – Tim Hofman
    Feb 28, 2014 at 21:54
  • yeah I learned a big tip from you,you solved my problem that i am struggling from the morning
    – Nickool
    Feb 28, 2014 at 22:02

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.