From 18f4a6f58f78031c2f237e6d2f89ba5a32c76dae Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Thu, 11 Mar 2021 18:57:56 +0530 Subject: [PATCH] Wishlist Check Fixed --- .../Http/Controllers/WishlistController.php | 16 +++++----- .../src/Repositories/WishlistRepository.php | 32 +++++++++++-------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php b/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php index 629288d0c..2a8467fac 100755 --- a/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php @@ -2,14 +2,14 @@ namespace Webkul\Customer\Http\Controllers; +use Cart; use Webkul\Product\Repositories\ProductRepository; use Webkul\Customer\Repositories\WishlistRepository; -use Cart; class WishlistController extends Controller { /** - * Contains route related configuration + * Contains route related configuration. * * @var array */ @@ -57,7 +57,7 @@ class WishlistController extends Controller */ public function index() { - $wishlistItems = $this->wishlistRepository->getCustomerWhishlist(); + $wishlistItems = $this->wishlistRepository->getCustomerWishlist(); if (! core()->getConfigData('general.content.shop.wishlist_option')) { abort(404); @@ -91,7 +91,7 @@ class WishlistController extends Controller 'customer_id' => auth()->guard('customer')->user()->id, ]); - //accidental case if some one adds id of the product in the anchor tag amd gives id of a variant. + // accidental case if some one adds id of the product in the anchor tag amd gives id of a variant. if ($product->parent_id != null) { $product = $this->productRepository->findOneByField('id', $product->parent_id); $data['product_id'] = $product->id; @@ -152,9 +152,9 @@ class WishlistController extends Controller public function move($itemId) { $wishlistItem = $this->wishlistRepository->findOneWhere([ - 'id' => $itemId, - 'customer_id' => auth()->guard('customer')->user()->id, - ]); + 'id' => $itemId, + 'customer_id' => auth()->guard('customer')->user()->id, + ]); if (! $wishlistItem) { abort(404); @@ -182,7 +182,7 @@ class WishlistController extends Controller } /** - * Function to remove all of the items items in the customer's wishlist + * Function to remove all of the items items in the customer's wishlist. * * @return \Illuminate\Http\Response */ diff --git a/packages/Webkul/Customer/src/Repositories/WishlistRepository.php b/packages/Webkul/Customer/src/Repositories/WishlistRepository.php index 3ab454a7a..a99320588 100755 --- a/packages/Webkul/Customer/src/Repositories/WishlistRepository.php +++ b/packages/Webkul/Customer/src/Repositories/WishlistRepository.php @@ -7,17 +7,18 @@ use Webkul\Core\Eloquent\Repository; class WishlistRepository extends Repository { /** - * Specify Model class name + * Specify model class name. * * @return mixed */ - function model() { return 'Webkul\Customer\Contracts\Wishlist'; } /** + * Create wishlist. + * * @param array $data * @return \Webkul\Customer\Contracts\Wishlist */ @@ -29,6 +30,8 @@ class WishlistRepository extends Repository } /** + * Update wishlist. + * * @param array $data * @param int $id * @param string $attribute @@ -55,25 +58,28 @@ class WishlistRepository extends Repository } /** - * get customer wishlist Items. + * Get customer wishlist items. * * @return \Illuminate\Support\Collection */ - public function getCustomerWhishlist() + public function getCustomerWishlist() { - $query = $this->model; + /* due to ambigious ids only selecting from wishlist table */ + $query = $this->model->select('wishlist.*'); + /* don't add product repository method as that one will need a product flat table */ 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); - }); + $query = $query + ->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); + }); } + /* main check to determine the wishlist */ return $query->where([ 'channel_id' => core()->getCurrentChannel()->id, 'customer_id' => auth()->guard('customer')->user()->id,