Tuesday, 20 August 2013

Adding custom attributes as filters in Magento product collection

Adding custom attributes as filters in Magento product collection

I'm trying to retrieve a product collection filtered by a custom attribute
I created which is location. I've created this code call the said
collection:
$_collection = Mage::getResourceModel('reports/product_collection')
->addAttributeToFilter('type_id', 'configurable')
->addAttributeToFilter('location', $_location);
This worked for other the system attributes of Magento however I can't
seem to make it work in my custom attribute. I have at least 1 product per
location (USA, Europe, Asia) but I keep getting zero returns. I've tried
echoing my query and it got the correct location. Are product collections
filtered differently if custom attributes are created? is there something
I'm missing here? Please advise.
My custom attribute is a dropdown attribute on the admin side.

No comments:

Post a Comment