Magento: pre filter by multiple option custom attributes

Requirement: pre-filter products by customer group name to product attribute.
I was looking for the “proper” way of filtering items by multiple custom attribute settings, but couldn’t find out how.
So, the following is a brief explanation of how I’ve got this running in Magento 1.4.1.

There are two ways of editing core code in Magento.

  1. Wrong: edit files directly in app/code/core/Mage
  2. Right: extend modules and keep them in app/code/local/MyDevCompany

If you’re in a hurry, you might edit core files directly and then later copy the altered code out into correctly extended module files.
For most of my Magento work, this is the route I have taken: get it working in the core then extend it once I’m sure I’m messing with the correct file/method. Just be sure to copy the code out at some point before upgrading the core!

This is how I have extended _getProductCollection() in app/code/core/Mage/Catalog/Block/Product/List.php – the method which generates the product list when viewing a category.
The extended file would be saved to app/code/local/MyDevCompany/Catalog/Block/Product/List.php

Reason I have used such a long and ugly method: addAttributeToFilter() will only play ball with attribute value IDs.
By fetching possible attribute value text and IDs, flipping the data, we can successfully filter by human readable text.

Further reading on how to set up a module for extension, see http://www.magentocommerce.com/wiki/groups/174/changing_and_customizing_magento_code

3 thoughts on “Magento: pre filter by multiple option custom attributes”

  1. Hi. Im a noob. So now you know…
    I have no ideea what those dudes say ’bout modules in the page you entered.
    Could you please provide some… assistance?
    The theme im using dosent have multi layered nav… So I was counting on a tech wiz to solve this filtering issue!
    regardless of you answer (or silence) i thank you for your code!

    1. Hi Paul,

      I’m afraid that I no longer work on this project and my knowledge of the Magento system has left me.

      I hope that others are able to offer you more help 🙂

      Iain

Leave a Reply

Your email address will not be published. Required fields are marked *