Fix related products

This commit is contained in:
Amanmyrat 2023-11-15 23:29:06 +05:00
parent 21bc5c56d9
commit 3a7ae028a5
1 changed files with 4 additions and 6 deletions

View File

@ -54,20 +54,18 @@ class ProductRepository extends WProductRepository
parent::__construct($attributeRepository, $app);
}
/**
* @param string $categoryId
*
* @return \Illuminate\Support\Collection
*/
public function getProductsRelatedToCategoryNurgul($product = null, $limit)
public function getProductsRelatedToCategoryNurgul($categoryId = null, $limit)
{
$qb = $this->model->leftJoin('product_categories', 'products.id', '=', 'product_categories.product_id');
$product = $this->find($product);
if (count($product->categories)) {
$qb->where('product_categories.category_id', $product->categories->first()->id);
if ($categoryId) {
$qb->where('product_categories.category_id', $categoryId);
}
return $qb->paginate($limit);