I would like to know. How can i filter collection by attributes value as I am making filter api for app. Please check below code where i am filter the collection this is working for simple products but for configuration i'm facing an issue
foreach ($productInfo['attrs'] as $attr) {
if ($attr->code == 'price') {
foreach ($attr->values as $key => $value) {
$rr[] = explode("-", $value);
}
$min = min(array_column($rr, '0'));
$max = max(array_column($rr, '1'));
$collection->addAttributeToFilter('price', ['from' => $min, 'to' => $max]);
}
if ($attr->code != 'price' && $attr->code != 'cat' ) {
$collection->addAttributeToFilter($attr->code, array('eq' => $attr->values));
}
if ($attr->code == 'cat') {
// print_r($attr->values);
$collection->addCategoriesFilter(['in' =>$attr->values ]);
}
if ($attr->code == 'ram') {
// print_r($attr->values);
$collection->addFieldToFilter('ram', ['in' => $attr->values]);
}
}
where I am receiving the value on this format
{"customer_id":"10","category_id":"3","page":"1","sort":"1", "attrs":[
{
"code":"price","values":["1000-30000"]
},
{
"code":"ram","values":["6","7"]
},
{
"code":"color","values":["12"]
},
]}