Wishlist Check Fixed

This commit is contained in:
devansh bawari 2021-03-11 18:57:56 +05:30
parent 22397d1b2d
commit 18f4a6f58f
2 changed files with 27 additions and 21 deletions

View File

@ -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
*/

View File

@ -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,