1

I have an all.phtml page that I listed all products in here.

This code can get all products info but I want to list by attribute (like search)

$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
$fancybox = MAGE::helper('ThemeOptions')->getThemeOptions('fancybox' );
$grid = MAGE::helper('ThemeOptions')->getThemeOptions('grid' );

How can I do that?

  • What do you mean? Do you want all products filtered by size? I don't understand the question – Fabian Blechschmidt Feb 21 '14 at 15:13
  • There are 2 attributes for products. I want filtered by (for example) color and size or just color or just size. – Ibrahim Mumcu Feb 21 '14 at 15:15
1

The logic inside of the Mage_Catalog_Block_Product_List is very complex and depends on a lot of classes, e.g. the layer for layered navigation.

$this->getLoadedProductCollection() says it already, the collection is loaded, therefore it is not possible to add filters.

I think the easiest way is to hook into catalog_block_product_list_collection check whether the action is the one, you want to change (this event is thrown at various places) and then just add the filters with

$collection->addAttributeToFilter($attributeName, $value)

The alternative is to extend the list class and implement the method _beforeToHtml so you can do whatever you want. Then you have to change the block class in your layout.xml

  • After researched I found this is possible. Used this and worked very well. $_productCollection->clear()->addAttributeToFilter('room', '6')->load(); – Ibrahim Mumcu Feb 21 '14 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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