Add capability to serach via multiple categoryIds in the REST API

This commit is contained in:
nikolayandreev 2021-02-15 12:34:31 +02:00
parent 63d86f5def
commit b3e1c63fd3
1 changed files with 5 additions and 5 deletions

View File

@ -129,11 +129,11 @@ class ProductRepository extends Repository
}
/**
* @param int $categoryId
* @param string $categories
*
* @return \Illuminate\Support\Collection
*/
public function getAll($categoryId = null)
public function getAll($categories = null)
{
$params = request()->input();
@ -147,7 +147,7 @@ class ProductRepository extends Repository
$page = Paginator::resolveCurrentPage('page');
$repository = app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($params, $categoryId) {
$repository = app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($params, $categories) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$locale = request()->get('locale') ?: app()->getLocale();
@ -161,8 +161,8 @@ class ProductRepository extends Repository
->where('product_flat.locale', $locale)
->whereNotNull('product_flat.url_key');
if ($categoryId) {
$qb->where('product_categories.category_id', $categoryId);
if ($categories) {
$qb->whereIn('product_categories.category_id', explode(',', $categories));
}
if (! core()->getConfigData('catalog.products.homepage.out_of_stock_items')) {