From 174ab21fa763e0153dc169e2433f0e1b99eb1b2a Mon Sep 17 00:00:00 2001 From: prashant-webkul Date: Fri, 21 Sep 2018 18:57:27 +0530 Subject: [PATCH] Changed the cart to session dependent code only --- packages/Webkul/Cart/src/Cart.php | 40 +++++++++++------------- packages/Webkul/Cart/src/Models/Cart.php | 5 --- packages/Webkul/Core/src/Core.php | 3 +- public/themes/default/assets/js/shop.js | 4 --- 4 files changed, 20 insertions(+), 32 deletions(-) diff --git a/packages/Webkul/Cart/src/Cart.php b/packages/Webkul/Cart/src/Cart.php index a91dc12b6..d5b2a571a 100644 --- a/packages/Webkul/Cart/src/Cart.php +++ b/packages/Webkul/Cart/src/Cart.php @@ -27,18 +27,18 @@ use Cookie; class Cart { - protected $cart; + protected $cart; //item repository instance - protected $cartItem; + protected $cartItem; //cart item repository instance - protected $customer; + protected $customer; //customer repository instance - //Cookie expiry limit in minutes - protected $minutes; + protected $product; //product repository instance - protected $product; - - public function __construct(CartRepository $cart, CartItemRepository $cartItem, CustomerRepository $customer, $minutes = 150, ProductRepository $product) { + public function __construct(CartRepository $cart, + CartItemRepository $cartItem, + CustomerRepository $customer, + ProductRepository $product) { $this->customer = $customer; @@ -46,8 +46,6 @@ class Cart { $this->cartItem = $cartItem; - $this->minutes = $minutes; - $this->product = $product; } @@ -58,22 +56,20 @@ class Cart { * * @return mixed */ - public function createNewCart($id, $data) { - $cartData['channel_id'] = core()->getCurrentChannel()->id; if(auth()->guard('customer')->check()) { $data['customer_id'] = auth()->guard('customer')->user()->id; - $cartData['customer_full_name'] = auth()->guard('customer')->first_name .' '. auth()->guard('customer')->last_name; + $cartData['customer_full_name'] = auth()->guard('customer')->user()->first_name .' '. auth()->guard('customer')->user()->last_name; } if($cart = $this->cart->create($cartData)) { - + $data['cart_id'] = $cart->id; $data['product_id'] = $id; - if($result = $cart->items()->create($data)) { + if($result = $this->cartItem->create($data)) { session()->put('cart', $cart); session()->flash('success', 'Item Added To Cart Successfully'); @@ -94,13 +90,16 @@ class Cart { public function add($id, $data) { + // session()->forget('cart'); + + // return redirect()->back(); + if(session()->has('cart')) { $cart = session()->get('cart'); - $cartItems = $cart->items; + $cartItems = $cart->items()->get(); if(isset($cartItems)) { - foreach($cartItems as $cartItem) { if($cartItem->product_id == $id) { $prevQty = $cartItem->quantity; @@ -151,7 +150,6 @@ class Cart { * with the existing data of cart * in the cart tables; */ - public function mergeCart() { if(session()->has('cart')) { $cart = session()->get('cart'); @@ -168,7 +166,7 @@ class Cart { foreach($cartItems as $key => $cartItem) { - if($cartItem->product_id == $customerCartItem->id) { + if($cartItem->product_id == $customerCartItem->product_id) { $customerItemQuantity = $customerCartItem->quantity; @@ -176,9 +174,9 @@ class Cart { $customerCartItem->update(['cart_id' => $customerCart->id, 'quantity' => $cartItemQuantity + $customerItemQuantity]); - $cartItem->destroy(); + $this->cartItem->delete($cartItem->id); - unset($cartItems[$key]); + $cartItems->forget($key); } } } diff --git a/packages/Webkul/Cart/src/Models/Cart.php b/packages/Webkul/Cart/src/Models/Cart.php index eb1d92950..734897522 100644 --- a/packages/Webkul/Cart/src/Models/Cart.php +++ b/packages/Webkul/Cart/src/Models/Cart.php @@ -15,11 +15,6 @@ class Cart extends Model protected $hidden = ['coupon_code']; - public function with_products() { - - return $this->belongsToMany(Product::class, 'cart_items')->withPivot('id', 'product_id','quantity', 'cart_id'); - } - public function items() { return $this->hasMany('Webkul\Cart\Models\CartItem'); } diff --git a/packages/Webkul/Core/src/Core.php b/packages/Webkul/Core/src/Core.php index 0b5d36e49..4457259e3 100644 --- a/packages/Webkul/Core/src/Core.php +++ b/packages/Webkul/Core/src/Core.php @@ -140,8 +140,7 @@ class Core $channel = $this->getCurrentChannel(); - $currencyCode = $channel->base_currency->code; - // $currencyCode = $channel->base_currency; + $currencyCode = $channel->base_currency; return currency($price, $currencyCode); } diff --git a/public/themes/default/assets/js/shop.js b/public/themes/default/assets/js/shop.js index f41490317..f5c835848 100644 --- a/public/themes/default/assets/js/shop.js +++ b/public/themes/default/assets/js/shop.js @@ -31659,10 +31659,6 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); initializeDropdown: function initializeDropdown() { this.totalitems = this.items.length; this.cart_items = this.items; -<<<<<<< HEAD -======= - console.log("The cart items here are = ", this.cart_items); ->>>>>>> 4c89e334f5b115301c5fbd345b50cb61b3c7d089 } } });