From 078d7e39dc08d2ba17d08d565ae2b57588f0ee2f Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Mon, 15 Mar 2021 18:28:09 +0530 Subject: [PATCH] Some Fixes Done --- .../src/Repositories/ProductRepository.php | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/Webkul/Product/src/Repositories/ProductRepository.php b/packages/Webkul/Product/src/Repositories/ProductRepository.php index de3320c86..0668b4b2a 100755 --- a/packages/Webkul/Product/src/Repositories/ProductRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductRepository.php @@ -811,6 +811,8 @@ class ProductRepository extends Repository } /** + * Check out of stock items. + * * @param Webkul\Product\Models\ProductFlat * * @return Model @@ -820,20 +822,23 @@ class ProductRepository extends Repository ->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 - ->where('ps.type', 'configurable') - ->where(function ($qb) { - $qb - ->selectRaw('SUM(' . DB::getTablePrefix() . 'product_inventories.qty)') - ->from('product_flat') - ->leftJoin('product_inventories', 'product_inventories.product_id', '=', 'product_flat.product_id') - ->whereRaw(DB::getTablePrefix() . 'product_flat.parent_id = ps.id'); - }, '>', 0); - }) - ->orWhere(function ($qb) { - $qb - ->WhereIn('ps.type', ['grouped', 'downloadable', 'bundle', 'booking']) - ->orwhereIn('ps.type', ['simple', 'virtual'])->where('pv.qty' , '>' , 0); + return $qb + /* for grouped, downloadable, bundle and booking product */ + ->orWhereIn('ps.type', ['grouped', 'downloadable', 'bundle', 'booking']) + /* for simple and virtual product */ + ->orWhere(function ($qb) { + return $qb->whereIn('ps.type', ['simple', 'virtual'])->where('pv.qty', '>', 0); + }) + /* for configurable product */ + ->orWhere(function ($qb) { + return $qb->where('ps.type', 'configurable')->where(function ($qb) { + return $qb + ->selectRaw('SUM(' . DB::getTablePrefix() . 'product_inventories.qty)') + ->from('product_flat') + ->leftJoin('product_inventories', 'product_inventories.product_id', '=', 'product_flat.product_id') + ->whereRaw(DB::getTablePrefix() . 'product_flat.parent_id = ps.id'); + }, '>', 0); + }); }); } } \ No newline at end of file