add filtering by properties
This commit is contained in:
@@ -48,6 +48,7 @@ class ProductFilterer
|
|||||||
'min_price' => ['nullable', 'numeric'],
|
'min_price' => ['nullable', 'numeric'],
|
||||||
'max_price' => ['nullable', 'numeric'],
|
'max_price' => ['nullable', 'numeric'],
|
||||||
'backorder' => ['nullable', 'in:0,1'],
|
'backorder' => ['nullable', 'in:0,1'],
|
||||||
|
'properties' => ['nullable', 'array'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,6 +94,18 @@ class ProductFilterer
|
|||||||
$this->queryBuilder->where('products.backorder', $this->request->backorder);
|
$this->queryBuilder->where('products.backorder', $this->request->backorder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->request->filled('properties')) {
|
||||||
|
foreach ($this->request->input('properties') as $attributeSlug => $values) {
|
||||||
|
$valuesArray = explode(',', $values);
|
||||||
|
|
||||||
|
$this->queryBuilder->where(function ($query) use ($attributeSlug, $valuesArray) {
|
||||||
|
foreach ($valuesArray as $value) {
|
||||||
|
$query->orWhereJsonContains("properties_json->{$attributeSlug}", $value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $this->queryBuilder;
|
return $this->queryBuilder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user