Question

I've got a very strange problem. I created a custom attribute named "taille_ecran" which mean in english "screen size". The labels of this attribute are numbers like 1.2, 1.6, 2, 5, 6, etc...

When I try to add a custom filter like this :

$_productCollection->addAttributeToSelect('taille_ecran');
$_productCollection->addFieldToFilter(array(
    array('attribute'=>'taille_ecran','lteq'=>$_GET['max_size']),
));

The filter filters by the option_id of thoses labels in "taille_ecran" instead of labels values. In fact, here is the ID of my labels :

31 => 1.2 41 => 5 etc...

When I tried to get the labels "lteq" under 7 there is no result and when I try 35 I get 1 result which is 1.2.

I try also to print this value in my products list :

echo $_product->getTailleEcran();

// print 31 when it's for 1.2...

It's very hard for me to explain clearly what is happening. I don't have this problem with other attribute.

Thanks in advance for your help !

Was it helpful?

Solution 3

Thanks to Fabian and Kiatng here is what I've done to solve this issue. I created a new custom attribute and beside using Drop Down I used Price.

That's permit me to not change my source code and now it's working.

Hope it'll help!

OTHER TIPS

Try this:

$attribute = Mage::getSingleton('catalog/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'taille_ecran');
$source = $attribute->getSource();
$optionId = $source->getOptionId($_GET['max_size']);
$_productCollection->addAttributeToFilter('taille_ecran', array('lteq'=>$optionId));

What you want to achieve is not supported by magento. Option filters are based on the option id, this means you are not able to filter by the value.

If you want this, you have to create your own attribute, add it as decimal and have your own source model with value = key, so you still have a select in the backend but you can filter by the value.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top