This commit is contained in:
Mekan1206
2026-05-04 13:34:54 +05:00
parent f365bff782
commit 14b47d40e8

View File

@@ -46,7 +46,7 @@ class FilterController extends Controller
}
if ($this->shouldFilterByCollection()) {
return $this->categoriesFor();
return $this->categoriesFor($this->request->collection_id, 'collection');
}
if ($this->shouldFilterByBrand()) {
@@ -54,7 +54,7 @@ class FilterController extends Controller
}
if ($this->shouldFilterByChannel()) {
return $this->filterByCategoryResource(Channel::find($this->request->channel_id));
return $this->filterByCategoryResource($this->request->channel_id, 'category');
}
return Category::query()->where('is_visible', true)->ordered()->get(['id', 'parent_id', 'name']);
@@ -115,20 +115,20 @@ class FilterController extends Controller
/**
* Categories for a resource
*/
private function categoriesFor($resource)
private function categoriesFor(int $id, string $type)
{
return DB::table('categories as c')
->select('c.id', 'c.parent_id', 'c.name')
->where('c.is_visible', true)
->whereExists(function ($query) {
->whereExists(function ($query) use ($id, $type) {
$query->select(DB::raw(1))
->from('product_has_relations as phr_cat')
->join('products as p', 'p.id', '=', 'phr_cat.product_id')
->join('product_has_relations as phr_chan', 'phr_chan.product_id', '=', 'p.id')
->whereColumn('phr_cat.productable_id', 'c.id')
->where('phr_cat.productable_type', 'category')
->where('phr_chan.productable_type', 'channel')
->where('phr_chan.productable_id', 6)
->where('phr_chan.productable_type', $type)
->where('phr_chan.productable_id', $id)
->where('p.is_visible', true)
->whereNull('p.parent_id')
->where('p.stock', '>', 0);