From e1f65b0614c297941d3f4cd14157aebb98caf2a9 Mon Sep 17 00:00:00 2001 From: Amanmyrat Date: Fri, 15 Sep 2023 22:08:05 +0500 Subject: [PATCH] Change related product logic --- .../Sarga/Shop/src/Repositories/ProductRepository.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/Sarga/Shop/src/Repositories/ProductRepository.php b/packages/Sarga/Shop/src/Repositories/ProductRepository.php index d94661f..f73990a 100644 --- a/packages/Sarga/Shop/src/Repositories/ProductRepository.php +++ b/packages/Sarga/Shop/src/Repositories/ProductRepository.php @@ -60,12 +60,14 @@ class ProductRepository extends WProductRepository * @return \Illuminate\Support\Collection */ - public function getProductsRelatedToCategoryNurgul($categoryId = null, $limit) + public function getProductsRelatedToCategoryNurgul($product = null, $limit) { $qb = $this->model->leftJoin('product_categories', 'products.id', '=', 'product_categories.product_id'); - if ($categoryId) { - $qb->where('product_categories.category_id', $categoryId); + $product = $this->find($product); + + if (count($product->categories)) { + $qb->where('product_categories.category_id', $product->categories->first->id); } return $qb->paginate($limit);