Hi,
I have a query and want to use multiple matches I have done the following and when it uses one attribute it works, but when I use multiple attributes it returns empty array, does anyone have an idea how to solve this?
I am using separate table with attributes, because I want to use attributesets for different type of products…
if($this->request->query(‘Color’)){
$match[] = [‘ProductsAttributes.eav IN’ => $this->request->query(‘Color’),‘ProductsAttributes.attribute_id’ => ‘20’];
}
if($this->request->query(‘Brand’)){
$match[] = [‘ProductsAttributes.eav IN’ => $this->request->query(‘Brand’),‘ProductsAttributes.attribute_id’ => ‘22’];
}
if (isset($match)){
$query = $this->Products
->find('search', ['search' => $this->request->query])
->contain(['Categories'])
->matching('Attributes', function ($query) use ($match) {
return $query
->where($match);
})
->where($where);
}else{
$query = $this->Products
->find('search', ['search' => $this->request->query])
->contain(['Categories'])
->where($where);
}