Cart Bug fixes -> Cart page intolerant to totals, fixed by executing helpers before redirecting on success.

This commit is contained in:
prashant-webkul 2018-10-04 15:58:44 +05:30
parent 217f57abc0
commit fc7cfd7d81
18 changed files with 141 additions and 193 deletions

View File

@ -83,7 +83,7 @@ class Cart {
}
/**
* Prepare the other data for the product to be added.
* Prepare the other data for the product to be success.
*
* @param integer $id
* @param array $data
@ -98,12 +98,12 @@ class Cart {
//Check if the product is salable
if(!isset($data['product']) ||!isset($data['quantity'])) {
session()->flash('error', 'Cart System Integrity Violation, Some Required Fields Missing.');
session()->flash('error', trans('shop::app.checkout.cart.integrity.missing_fields'));
return redirect()->back();
} else {
if($product->type == 'configurable' && !isset($data['super_attribute'])) {
session()->flash('error', 'Cart System Integrity Violation, Configurable Options Not Found In Request.');
session()->flash('error', trans('shop::app.checkout.cart.integrity.missing_options'));
return redirect()->back();
}
@ -153,13 +153,12 @@ class Cart {
'total_weight' => $product->weight * $data['quantity'],
'base_total_weight' => $product->weight * $data['quantity'],
];
return ['parent' => $parentData, 'child' => null];
}
}
/**
* Create new cart instance with the current item added.
* Create new cart instance with the current item success.
*
* @param integer $id
* @param array $data
@ -178,7 +177,9 @@ class Cart {
$cartData['is_guest'] = 0;
$cartData['customer_full_name'] = auth()->guard('customer')->user()->first_name .' '. auth()->guard('customer')->user()->last_name;
$cartData['customer_first_name'] = auth()->guard('customer')->user()->first_name;
$cartData['customer_last_name'] = auth()->guard('customer')->user()->last_name;
} else {
$cartData['is_guest'] = 1;
}
@ -191,42 +192,41 @@ class Cart {
$itemData['parent']['cart_id'] = $cart->id;
if ($data['is_configurable'] == "true") {
//parent product entry
//parent item entry
$itemData['parent']['additional'] = json_encode($data);
if($parent = $this->cartItem->create($itemData['parent'])) {
//child item entry
$itemData['child']['parent_id'] = $parent->id;
$itemData['child']['cart_id'] = $cart->id;
if($child = $this->cartItem->create($itemData['child'])) {
session()->put('cart', $cart);
session()->flash('success', 'Item Added To Cart Successfully');
session()->flash('success', trans('shop::app.checkout.cart.item.success'));
$this->collectQuantities();
$this->collectTotals();
return redirect()->back();
}
}
// $cart->update(['subtotal' => $itemData['parent']['price'], 'base_sub_total' => $itemData['parent']['price']]);
$this->collectQuantities();
$this->collectTotals();
} else if($data['is_configurable'] == "false") {
if($result = $this->cartItem->create($itemData['parent'])) {
session()->put('cart', $cart);
session()->flash('success', 'Item Added To Cart Successfully');
session()->flash('success', trans('shop::app.checkout.cart.item.success'));
$this->collectQuantities();
$this->collectTotals();
return redirect()->back();
}
// $cart->update(['subtotal' => $itemData['parent']['price'], 'base_sub_total' => $itemData['parent']['price']]);
$this->collectQuantities();
$this->collectTotals();
}
}
session()->flash('error', 'Some Error Occured');
session()->flash('error', trans('shop::app.checkout.cart.item.error_add'));
return redirect()->back();
}
@ -269,7 +269,7 @@ class Cart {
}
if ($quantity < 1) {
session()->flash('warning', 'Cannot Add Or Update Lesser than 1');
session()->flash('warning', trans('shop::app.checkout.cart.quantity.warning'));
return redirect()->back();
}
@ -309,7 +309,7 @@ class Cart {
$canBe = $this->canAddOrUpdate($cartItem->id, $prevQty + $newQty);
if($canBe == false) {
session()->flash('warning', 'The requested quantity is not available, please try back later.');
session()->flash('warning', trans('shop::app.checkout.cart.quantity.inventory_warning'));
return redirect()->back();
}
@ -324,7 +324,7 @@ class Cart {
$this->collectTotals();
session()->flash('success', "Product Quantity Successfully Updated");
session()->flash('success', trans('shop::app.checkout.cart.quantity.success'));
return redirect()->back();
}
@ -343,7 +343,7 @@ class Cart {
$canBe = $this->canAddOrUpdate($cartItem->child->id, $prevQty + $newQty);
if($canBe == false) {
session()->flash('warning', 'The requested quantity is not available, please try back later.');
session()->flash('warning', trans('shop::app.checkout.cart.quantity.inventory_warning'));
return redirect()->back();
}
@ -358,7 +358,7 @@ class Cart {
$this->collectTotals();
session()->flash('success', "Product Quantity Successfully Updated");
session()->flash('success', trans('shop::app.checkout.cart.quantity.success'));
return redirect()->back();
}
@ -384,7 +384,7 @@ class Cart {
$this->collectTotals();
session()->flash('success', 'Item Successfully Added To Cart');
session()->flash('success', trans('shop::app.checkout.cart.item.success'));
return redirect()->back();
} else {
@ -420,7 +420,7 @@ class Cart {
}
if($canBe == false) {
session()->flash('warning', 'The requested quantity is not available, please try back later.');
session()->flash('warning', trans('shop::app.checkout.cart.quantity.inventory_warning'));
return redirect()->back();
}
@ -432,7 +432,7 @@ class Cart {
$items = $cart->items;
session()->flash('success', 'Cart Updated Successfully');
session()->flash('success', trans('shop::app.checkout.cart.quantity.success'));
return redirect()->back();
}
@ -445,7 +445,6 @@ class Cart {
*/
public function removeItem($itemId)
{
dd($itemId);
if(session()->has('cart')) {
$cart = session()->get('cart');
@ -485,13 +484,11 @@ class Cart {
}
if ($result) {
session()->flash('sucess', trans('shop::app.checkout.cart.remove.success'));
session()->flash('sucess', trans('shop::app.checkout.cart.quantity.success_remove'));
} else {
session()->flash('error', trans('shop::app.checkout.cart.remove.error'));
session()->flash('error', trans('shop::app.checkout.cart.quantity.error_remove'));
}
}
session()->flash('warning', trans('shop::app.checkout.cart.remove.cannot'));
return redirect()->back();
}
@ -504,21 +501,14 @@ class Cart {
{
$data = [];
$labels = [];
foreach($item->product->super_attributes as $attribute) {
$option = $attribute->options()->where('id', $item->child->product->{$attribute->code})->first();
$option = $attribute->options()->where('id', $item->child->{$attribute->code})->first();
$data['attributes'][$attribute->code] = [
'attribute_name' => $attribute->name,
'option_label' => $option->label,
];
$labels[] = $attribute->name . ' : ' . $option->label;
}
$data['html'] = implode(', ', $labels);
return $data;
}

View File

@ -27,8 +27,8 @@ class CreateCartTable extends Migration
$table->decimal('exchange_rate', 12, 4)->nullable();
$table->string('global_currency_code')->nullable();
$table->string('base_currency_code')->nullable();
$table->string('store_currency_code')->nullable();
$table->string('quote_currency_code')->nullable();
$table->string('channel_currency_code')->nullable();
$table->string('cart_currency_code')->nullable();
$table->decimal('grand_total', 12, 4)->default(0)->nullable();
$table->decimal('base_grand_total', 12, 4)->default(0)->nullable();
$table->decimal('sub_total', 12, 4)->default(0)->nullable();
@ -38,7 +38,9 @@ class CreateCartTable extends Migration
$table->string('checkout_method')->nullable();
$table->boolean('is_guest')->nullable();
$table->boolean('is_active')->nullable()->default(0);
$table->string('customer_full_name')->nullable();
$table->string('customer_first_name')->nullable();
$table->string('customer_last_name')->nullable();
$table->string('customer_email')->nullable();
$table->dateTime('conversion_time')->nullable();
$table->timestamps();
});

View File

@ -13,7 +13,7 @@ class Cart extends Model
{
protected $table = 'cart';
protected $fillable = ['customer_id', 'session_id', 'channel_id', 'coupon_code', 'is_gift', 'items_count', 'items_qty', 'exchange_rate', 'global_currency_code', 'base_currency_code', 'store_currency_code', 'quote_currency_code', 'grand_total', 'base_grand_total', 'sub_total', 'base_sub_total', 'sub_total_with_discount', 'base_sub_total_with_discount', 'checkout_method', 'is_guest', 'is_active', 'customer_full_name', 'conversion_time'];
protected $fillable = ['customer_id', 'session_id', 'channel_id', 'coupon_code', 'is_gift', 'items_count', 'items_qty', 'exchange_rate', 'global_currency_code', 'base_currency_code', 'channel_currency_code', 'cart_currency_code', 'grand_total', 'base_grand_total', 'sub_total', 'base_sub_total', 'sub_total_with_discount', 'base_sub_total_with_discount', 'checkout_method', 'is_guest', 'is_active', 'customer_first_name', 'conversion_time'];
protected $hidden = ['coupon_code'];

View File

@ -17,10 +17,13 @@ class CreateWishlistTable extends Migration
$table->increments('id');
$table->integer('channel_id')->unsigned();
$table->foreign('channel_id')->references('id')->on('channels');
$table->integer('product_id')->unsigned();
$table->foreign('product_id')->references('id')->on('products');
$table->integer('customer_id')->unsigned();
$table->foreign('customer_id')->references('id')->on('customers')->onDelete('cascade');
$table->json('item_options')->nullable();
$table->date('moved_to_cart')->nullable();
$table->boolean('shared')->nullable();

View File

@ -55,7 +55,30 @@ class WishlistController extends Controller
return view($this->_config['view'])->with('customer', $customer);
}
public function wishlist() {
return view($this->_config['view']);
/**
* Function to add item to the wishlist.
*
* @param integer $itemId
*/
public function add() {
dd('adding item to wishlist');
}
/**
* Function to remove item to the wishlist.
*
* @param integer $itemId
*/
public function remove($itemId) {
dd('removing item to wishlist');
}
/**
* Function to move item from wishlist to cart.
*
* @param integer $itemId
*/
public function moveToCart() {
dd('adding item to wishlist');
}
}

View File

@ -10,10 +10,23 @@ Route::group(['middleware' => ['web']], function () {
'view' => 'shop::products.index'
]);
Route::get('/checkout/cart', 'Webkul\Shop\Http\Controllers\CartController@index')->defaults('_config', [
Route::get('checkout/cart', 'Webkul\Shop\Http\Controllers\CartController@index')->defaults('_config', [
'view' => 'shop::checkout.cart.index'
])->name('shop.checkout.cart.index');
Route::post('checkout/cart/add/{id}', 'Webkul\Shop\Http\Controllers\CartController@add')->name('cart.add');
Route::get('checkout/cart/remove/{id}', 'Webkul\Shop\Http\Controllers\CartController@remove')->name('cart.remove');
Route::post('/checkout/cart', 'Webkul\Shop\Http\Controllers\CartController@updateBeforeCheckout')->defaults('_config',[
'redirect' => 'shop.checkout.cart.index'
])->name('shop.checkout.cart.update');
Route::get('/checkout/cart/remove/{id}', 'Webkul\Shop\Http\Controllers\CartController@remove')->defaults('_config',[
'redirect' => 'shop.checkout.cart.index'
])->name('shop.checkout.cart.remove');
//Routes for product cart ends
Route::get('/checkout/onepage', 'Webkul\Shop\Http\Controllers\OnepageController@index')->defaults('_config', [
'view' => 'shop::checkout.onepage'
])->name('shop.checkout.onepage.index');
@ -30,10 +43,6 @@ Route::group(['middleware' => ['web']], function () {
'view' => 'shop::checkout.success'
])->name('shop.checkout.success');
Route::get('test', 'Webkul\Shop\Http\Controllers\CartController@test');
Route::get('mtest', 'Webkul\Shop\Http\Controllers\CartController@mergeTest');
//dummy
Route::get('test', 'Webkul\Shop\Http\Controllers\CartController@test');
@ -41,18 +50,6 @@ Route::group(['middleware' => ['web']], function () {
'view' => 'shop::products.view'
])->name('shop.products.index');
Route::post('product/cart/add/{id}', 'Webkul\Shop\Http\Controllers\CartController@add')->name('cart.add');
Route::get('product/cart/remove/{id}', 'Webkul\Shop\Http\Controllers\CartController@remove')->name('cart.remove');
Route::post('/checkout/cart', 'Webkul\Shop\Http\Controllers\CartController@updateBeforeCheckout')->defaults('_config',[
'redirect' => 'shop.checkout.cart.index'
])->name('shop.checkout.cart.update');
Route::get('/checkout/cart/remove/{id}', 'Webkul\Shop\Http\Controllers\CartController@remove')->defaults('_config',[
'redirect' => 'shop.checkout.cart.index'
])->name('shop.checkout.cart.remove');
//Routes for product cart ends
// Product Review routes
Route::get('/reviews/{slug}', 'Webkul\Shop\Http\Controllers\ReviewController@show')->defaults('_config', [

View File

@ -1050,28 +1050,20 @@ section.product-detail {
max-height: 480px;
}
.whishlist-icon {
margin-top: -480px;
float: right;
margin-right: 10px;
.wishlist-icon {
position: absolute;
height: 32px;
width: 32px;
top: 15px;
right: 15px;
}
.share-icon {
margin-top: -480px;
float: right;
margin-right: 40px;
}
.wishlist {
position: absolute;
top: 10px;
right: 12px;
}
.share {
position: absolute;
top: 10px;
right: 45px;
height: 32px;
width: 32px;
top: 15px;
right: 48px;
}
}
}

View File

@ -91,15 +91,16 @@
white-space: nowrap;
}
.product-card.wishlist-icon {
cursor: pointer;
}
}
}
//wishlist-icon-hover
.product-card.wishlist-icon:hover {
background-image: url('../images/wishadd.svg');
//wishlist icon hover properties
.add-to-wishlist {
.wishlist-icon {
&:hover {
background-image: url('../images/wishadd.svg');
}
}
}
//product page price styles

View File

@ -1,10 +1,6 @@
<?php
return [
'common' => [
'error' => 'Something went wrong, please contact us or try again later.'
],
'customer' => [
'signup-text' => [
'account_exists' => 'Already have an account',
@ -64,21 +60,28 @@ return [
'checkout' => [
'cart' => [
'integrity' => [
'missing_fields' =>'Cart System Integrity Violation, Some Required Fields Missing',
'missing_options' =>'Cart System Integrity Violation, Configurable product\'s options are missing',
],
'title' => 'Shopping Cart',
'empty' => 'Shopping Cart Is Empty',
'continue-shopping' => 'Continue Shopping',
'proceed-to-checkout' => 'Proceed To Checkout',
'quantity' => 'Quantity',
'remove' => 'Remove',
'move-to-wishlist' => 'Move to Wishlist',
'quantity' => [
'quantity' => 'Quantity',
'illegal' => 'Quantity cannot be lesser than one.'
'success' => 'Quantity successfully updated',
'illegal' => 'Quantity cannot be lesser than one',
'inventory_warning' => 'The requested quantity is not available, please try again later'
],
'remove' => [
'cannot' => 'No items to remove from the cart',
'success' => 'Item successfully removed from the cart',
'error' => 'Cannot remove item from cart'
'item' => [
'error_remove' => 'No items to remove from the cart',
'success' => 'Item successfully added to cart',
'success_remove' => 'Item removed successfully',
'error_add' => 'Item cannot be added to cart',
]
],

View File

@ -85,7 +85,7 @@
<li class="cart-dropdown">
<span class="icon cart-icon"></span>
@if(isset($cart))
@if(isset($cart) && session()->has('cart'))
@php
$cartInstance = session()->get('cart');
@endphp
@ -200,7 +200,7 @@
<ul class="resp-cart-dropdown-container">
<li class="cart-dropdown">
@if(isset($cart))
@if(isset($cart) && session()->has('cart'))
@php
$cartInstance = session()->get('cart');
@endphp
@ -240,7 +240,9 @@
@else
<div class="dropdown-toggle">
<div style="display: inline-block; cursor: pointer;">
<span class="name"><span class="count"> 0 &nbsp;</span>Products</span>
{{-- <span class="name"><span class="count"> 0 &nbsp;
</span>Products</span> --}}
<span class="icon cart-icon"></span>
</div>
</div>
@endif
@ -256,60 +258,4 @@
@include('shop::layouts.header.nav-menu.navmenu')
</div>
</div>
{{-- @push('scripts')
<script>
window.onload = function() {
var hamMenu = document.getElementById("hammenu");
var search = document.getElementById("search");
var searchSuggestion = document.getElementsByClassName('search-suggestion')[0];
var headerBottom = document.getElementsByClassName('header-bottom')[0];
var nav= document.getElementsByClassName('nav-responsive')[0];
search.addEventListener("click", header);
hamMenu.addEventListener("click", header);
window.addEventListener('scroll', function() {
if(window.pageYOffset > 70){
headerBottom.style.visibility = "hidden";
}else{
headerBottom.style.visibility = "visible";
}
});
function header(){
var className = document.getElementById(this.id).className;
if(className === 'icon search-icon' ){
search.classList.remove("search-icon");
search.classList.add("cross-icon");
searchSuggestion.style.display = 'block';
document.body.style.overflow = 'hidden';
nav.style.display = 'none';
}else if(className === 'icon sortable-icon'){
hamMenu.classList.remove("sortable-icon");
hamMenu.classList.add("cross-icon");
searchSuggestion.style.display = 'none';
nav.style.display = 'block';
document.body.style.overflow = 'hidden';
}else{
search.classList.remove("cross-icon");
search.classList.add("search-icon");
hamMenu.classList.remove("cross-icon");
hamMenu.classList.add("sortable-icon");
searchSuggestion.style.display = 'none';
nav.style.display = 'none';
document.body.style.overflow = "scroll";
}
}
}
</script>
@endpush --}}
</div>

View File

@ -20,6 +20,7 @@
<body>
<div id="app">
<flash-wrapper ref='flashes'></flash-wrapper>
<div class="main-container-wrapper">

View File

@ -2,6 +2,6 @@
@include ('shop::products.add-to-cart', ['product' => $product])
<span class="product-card wishlist-icon"></span>
@include('shop::products.wishlist')
</div>

View File

@ -1,4 +1 @@
<div class="icon share-icon">
<a href="#"></a>
</div>
<span class="icon share-icon"></span>

View File

@ -32,10 +32,10 @@
<img :src="currentLargeImageUrl" id="pro-img"/>
<div class="icon whishlist-icon"> </div>
@include ('shop::products.sharelinks')
{{-- Uncomment the line below for activating share links --}}
{{-- @include('shop::products.sharelinks') --}}
@include('shop::products.wishlist')
</div>

View File

@ -0,0 +1,5 @@
@auth('customer')
<a class="add-to-wishlist" href="">
<span class="icon wishlist-icon"></span>
</a>
@endauth

View File

@ -178,11 +178,7 @@
white-space: nowrap;
}
.product-card .cart-fav-seg .product-card.wishlist-icon {
cursor: pointer;
}
.product-card.wishlist-icon:hover {
.add-to-wishlist .wishlist-icon:hover {
background-image: url("../images/wishadd.svg");
}
@ -1622,28 +1618,20 @@ section.product-detail div.layouter form div.product-image-group div .product-he
max-height: 480px;
}
section.product-detail div.layouter form div.product-image-group div .product-hero-image .whishlist-icon {
margin-top: -480px;
float: right;
margin-right: 10px;
section.product-detail div.layouter form div.product-image-group div .product-hero-image .wishlist-icon {
position: absolute;
height: 32px;
width: 32px;
top: 15px;
right: 15px;
}
section.product-detail div.layouter form div.product-image-group div .product-hero-image .share-icon {
margin-top: -480px;
float: right;
margin-right: 40px;
}
section.product-detail div.layouter form div.product-image-group div .product-hero-image .wishlist {
position: absolute;
top: 10px;
right: 12px;
}
section.product-detail div.layouter form div.product-image-group div .product-hero-image .share {
position: absolute;
top: 10px;
right: 45px;
height: 32px;
width: 32px;
top: 15px;
right: 48px;
}
section.product-detail div.layouter form div.product-image-group .add-to-buttons {

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{
"/js/shop.js": "/js/shop.js",
"/css/shop.css": "/css/shop.css"
}
}