I have Multiselect product attribute and i want to filter product by that attribute.
Currently i am using below code,
$productCollection = $this->getLayer()->getProductCollection();
$productCollection->addAttributeToFilter(
array(
array('attribute'=> 'fabriccolor','finset' => 16),
array('attribute'=> 'fabriccolor','finset' => 17),
)
);
echo $productCollection->getSelect();
The query i get like
SELECT
e
.*,cat_index
.position
AScat_index_position
,price_index
.price
,price_index
.tax_class_id
,price_index
.final_price
, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) ASminimal_price
,price_index
.min_price
,price_index
.max_price
,price_index
.tier_price
,at_fabriccolor
.value
ASfabriccolor
FROMcatalog_product_entity
ASe
INNER JOINcatalog_category_product_index_store1
AScat_index
ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.visibility IN(2, 4) AND cat_index.category_id=3 INNER JOINcatalog_product_index_price
ASprice_index
ON price_index.entity_id = e.entity_id AND price_index.customer_group_id = 0 AND price_index.website_id = '1' INNER JOINcatalog_product_entity_varchar
ASat_fabriccolor
ON (at_fabriccolor
.entity_id
=e
.entity_id
) AND (at_fabriccolor
.attribute_id
= '155') AND (at_fabriccolor
.store_id
= 0) WHERE ((FIND_IN_SET(16, at_fabriccolor.value)) OR (FIND_IN_SET(17, at_fabriccolor.value)))
The products i get which has fabriccolor value 16 or 17. Please check this screenshot,
But i want to filter the product which have both fabriccolor value 16 and 17 by code. I want to update the query from WHERE ((FIND_IN_SET(16,> at_fabriccolor.value)) OR (FIND_IN_SET(17, at_fabriccolor.value))) to WHERE ((FIND_IN_SET(16,> at_fabriccolor.value)) AND (FIND_IN_SET(17, at_fabriccolor.value))).
If i put the AND in the query then it gives me correct products which i want. Please check below screenshot,
So, how can i filter products by AND insted of OR. Please help me if you have any solution.
Thanks in Advance!!!