From db30a2e442d3545e0547c50a170d2877b8414c0f Mon Sep 17 00:00:00 2001 From: rahul shukla Date: Mon, 15 Feb 2021 15:38:08 +0530 Subject: [PATCH] fixes as per comment --- .../src/Repositories/WishlistRepository.php | 15 ++++++++++++++- .../src/Repositories/ProductRepository.php | 8 ++++---- packages/Webkul/Velocity/src/Helpers/Helper.php | 4 ++++ .../Repositories/Product/ProductRepository.php | 4 ++++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/Webkul/Customer/src/Repositories/WishlistRepository.php b/packages/Webkul/Customer/src/Repositories/WishlistRepository.php index 7d84f2a52..7e0258963 100755 --- a/packages/Webkul/Customer/src/Repositories/WishlistRepository.php +++ b/packages/Webkul/Customer/src/Repositories/WishlistRepository.php @@ -61,7 +61,20 @@ class WishlistRepository extends Repository */ public function getCustomerWhishlist() { - return $this->model->where([ + $query = $this->model; + + if (! core()->getConfigData('catalog.products.homepage.out_of_stock_items')) { + $query =$this->model + ->leftJoin('products as ps', 'wishlist.product_id', '=', 'ps.id') + ->leftJoin('product_inventories as pv', 'ps.id', '=', 'pv.product_id') + ->where(function ($qb) { + $qb + ->WhereIn('ps.type', ['configurable', 'grouped', 'downloadable', 'bundle', 'booking']) + ->orwhereIn('ps.type', ['simple', 'virtual'])->where('pv.qty' , '>' , 0); + }); + } + + return $query->where([ 'channel_id' => core()->getCurrentChannel()->id, 'customer_id' => auth()->guard('customer')->user()->id, ])->paginate(5); diff --git a/packages/Webkul/Product/src/Repositories/ProductRepository.php b/packages/Webkul/Product/src/Repositories/ProductRepository.php index a8718bfc4..dbbc10a50 100755 --- a/packages/Webkul/Product/src/Repositories/ProductRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductRepository.php @@ -812,12 +812,12 @@ class ProductRepository extends Repository * @return Model */ public function checkOutOfStockItem($query) { - return $query->leftJoin('products', 'product_flat.product_id', '=', 'products.id') - ->leftJoin('product_inventories', 'product_flat.product_id', '=', 'product_inventories.product_id') + return $query->leftJoin('products as ps', 'product_flat.product_id', '=', 'ps.id') + ->leftJoin('product_inventories as pv', 'product_flat.product_id', '=', 'pv.product_id') ->where(function ($qb) { $qb - ->WhereIn('products.type', ['configurable', 'grouped', 'downloadable', 'bundle', 'booking']) - ->orwhereIn('products.type', ['simple', 'virtual'])->where('product_inventories.qty' , '>' , 0); + ->WhereIn('ps.type', ['configurable', 'grouped', 'downloadable', 'bundle', 'booking']) + ->orwhereIn('ps.type', ['simple', 'virtual'])->where('pv.qty' , '>' , 0); }); } } \ No newline at end of file diff --git a/packages/Webkul/Velocity/src/Helpers/Helper.php b/packages/Webkul/Velocity/src/Helpers/Helper.php index c2cb28969..1d882b45b 100644 --- a/packages/Webkul/Velocity/src/Helpers/Helper.php +++ b/packages/Webkul/Velocity/src/Helpers/Helper.php @@ -380,6 +380,10 @@ class Helper extends Review // @TODO:- query only once insted of 2 $productFlat = $this->productFlatRepository->findOneWhere(['id' => $productId]); + if (! core()->getConfigData('catalog.products.homepage.out_of_stock_items') && ! $productFlat->isSaleable()) { + continue; + } + if ($productFlat) { $product = $this->productRepository->findOneWhere(['id' => $productFlat->product_id]); diff --git a/packages/Webkul/Velocity/src/Repositories/Product/ProductRepository.php b/packages/Webkul/Velocity/src/Repositories/Product/ProductRepository.php index 29d50283f..f1ba15725 100644 --- a/packages/Webkul/Velocity/src/Repositories/Product/ProductRepository.php +++ b/packages/Webkul/Velocity/src/Repositories/Product/ProductRepository.php @@ -116,6 +116,10 @@ class ProductRepository extends Repository $locale = request()->get('locale') ?: app()->getLocale(); + if (! core()->getConfigData('catalog.products.homepage.out_of_stock_items')) { + $query = app('Webkul\Product\Repositories\ProductRepository')->checkOutOfStockItem($query); + } + $query = $query->distinct() ->addSelect('product_flat.*') ->leftJoin('products', 'product_flat.product_id', '=', 'products.id')