Changed the cart to session dependent code only
This commit is contained in:
parent
45a8611fa3
commit
174ab21fa7
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue