code to filter product by attribute by color in ma

2019-08-28 01:41发布

问题:

I need to implement product filter by colour, size list page. I have created one mega menu and want to implement this.

Any idea , how to fix this?

回答1:

Either you can implement using code i.e,

$productCollection =Mage::getModel('catalog/product')->getCollection()
                           ->addAttributeToFilter('color',{{color-option-id}})
                           ->addAttributeToFilter('size',{{size-option-id}});

Other filter options can be found in https://www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento

This is through code, if you are talking about layered navigation, then http://www.magentocommerce.com/knowledge-base/entry/how-does-layered-navigation-work

Please let me know if this works!