Multiselct product attribute is not beign added into collection filtering
-
02-01-2021 - |
Вопрос
I have created a multi select attribute and assigned this to attribute set. Attribute is showing in product search results but I am unable to include this into product collection filtering as well as into addAttributeToSelct Here is the section I am using this attribute to filter the prodcut collection.
$collection = Mage::getModel("catalog/product")
->getCollection()
->addAttributeToSelect(array('sku','speciality','name'))
->addFieldToFilter('speciality', array('eq' => $speciality));
echo $collection->getSelect();
And in my browser I have the following result for select query
SELECT `e`.`entity_id`, `e`.`type_id`, `e`.`attribute_set_id`, `e`.`sku`, `e`.`name` FROM `catalog_product_flat_3` AS `e` WHERE (e.status = 1)
Решение
At first look, I see two points that could help you :
1) It seems that you are using the flat_catalog
feature. And, as your attribute speciality
is set to be Used in product listing
, you have to reindex product_flat
index before to be able to retrieve it in your collection.
2) I think you should use addAttributeToFilter
instead of addFieldToFilter
too.