From fc7cfd7d81d66716ae081dab411c28160f32d42c Mon Sep 17 00:00:00 2001 From: prashant-webkul Date: Thu, 4 Oct 2018 15:58:44 +0530 Subject: [PATCH 1/8] Cart Bug fixes -> Cart page intolerant to totals, fixed by executing helpers before redirecting on success. --- packages/Webkul/Checkout/src/Cart.php | 72 ++++++++----------- .../2018_09_05_150444_create_cart_table.php | 8 ++- packages/Webkul/Checkout/src/Models/Cart.php | 2 +- ...018_10_03_025230_create_wishlist_table.php | 3 + .../Http/Controllers/WishlistController.php | 27 ++++++- packages/Webkul/Shop/src/Http/routes.php | 31 ++++---- .../Shop/src/Resources/assets/sass/app.scss | 28 +++----- .../src/Resources/assets/sass/components.scss | 13 ++-- .../Webkul/Shop/src/Resources/lang/en/app.php | 23 +++--- .../views/layouts/header/index.blade.php | 66 ++--------------- .../Resources/views/layouts/master.blade.php | 1 + .../Resources/views/products/add-to.blade.php | 2 +- .../views/products/sharelinks.blade.php | 5 +- .../views/products/view/gallery.blade.php | 6 +- .../views/products/wishlist.blade.php | 5 ++ public/themes/default/assets/css/shop.css | 34 +++------ public/themes/default/assets/js/shop.js | 6 +- .../themes/default/assets/mix-manifest.json | 2 +- 18 files changed, 141 insertions(+), 193 deletions(-) create mode 100644 packages/Webkul/Shop/src/Resources/views/products/wishlist.blade.php diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index eb4924901..175ba88c1 100644 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -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; } diff --git a/packages/Webkul/Checkout/src/Database/Migrations/2018_09_05_150444_create_cart_table.php b/packages/Webkul/Checkout/src/Database/Migrations/2018_09_05_150444_create_cart_table.php index b142835c8..0a9987253 100644 --- a/packages/Webkul/Checkout/src/Database/Migrations/2018_09_05_150444_create_cart_table.php +++ b/packages/Webkul/Checkout/src/Database/Migrations/2018_09_05_150444_create_cart_table.php @@ -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(); }); diff --git a/packages/Webkul/Checkout/src/Models/Cart.php b/packages/Webkul/Checkout/src/Models/Cart.php index eb7938a66..f5a0f77c6 100644 --- a/packages/Webkul/Checkout/src/Models/Cart.php +++ b/packages/Webkul/Checkout/src/Models/Cart.php @@ -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']; diff --git a/packages/Webkul/Customer/src/Database/migrations/2018_10_03_025230_create_wishlist_table.php b/packages/Webkul/Customer/src/Database/migrations/2018_10_03_025230_create_wishlist_table.php index 08f8adae4..68ca95edb 100644 --- a/packages/Webkul/Customer/src/Database/migrations/2018_10_03_025230_create_wishlist_table.php +++ b/packages/Webkul/Customer/src/Database/migrations/2018_10_03_025230_create_wishlist_table.php @@ -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(); diff --git a/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php b/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php index fb8567d66..d2335e1ae 100644 --- a/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php @@ -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'); } } diff --git a/packages/Webkul/Shop/src/Http/routes.php b/packages/Webkul/Shop/src/Http/routes.php index dff2ea127..cb7277631 100644 --- a/packages/Webkul/Shop/src/Http/routes.php +++ b/packages/Webkul/Shop/src/Http/routes.php @@ -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', [ diff --git a/packages/Webkul/Shop/src/Resources/assets/sass/app.scss b/packages/Webkul/Shop/src/Resources/assets/sass/app.scss index 71227fb36..8b3ebb2f4 100644 --- a/packages/Webkul/Shop/src/Resources/assets/sass/app.scss +++ b/packages/Webkul/Shop/src/Resources/assets/sass/app.scss @@ -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; } } } diff --git a/packages/Webkul/Shop/src/Resources/assets/sass/components.scss b/packages/Webkul/Shop/src/Resources/assets/sass/components.scss index 78a22e599..5f3d4ddbb 100644 --- a/packages/Webkul/Shop/src/Resources/assets/sass/components.scss +++ b/packages/Webkul/Shop/src/Resources/assets/sass/components.scss @@ -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 diff --git a/packages/Webkul/Shop/src/Resources/lang/en/app.php b/packages/Webkul/Shop/src/Resources/lang/en/app.php index 2c47d91ba..5712b7e08 100644 --- a/packages/Webkul/Shop/src/Resources/lang/en/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/en/app.php @@ -1,10 +1,6 @@ [ - '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', ] ], diff --git a/packages/Webkul/Shop/src/Resources/views/layouts/header/index.blade.php b/packages/Webkul/Shop/src/Resources/views/layouts/header/index.blade.php index e81596070..c054b889e 100644 --- a/packages/Webkul/Shop/src/Resources/views/layouts/header/index.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/layouts/header/index.blade.php @@ -85,7 +85,7 @@
  • - @if(isset($cart)) + @if(isset($cart) && session()->has('cart')) @php $cartInstance = session()->get('cart'); @endphp @@ -200,7 +200,7 @@ - - @endguest @auth('customer')