From da82f2935c30a660a97358722385e174aca20dbc Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Fri, 14 Jun 2019 17:54:36 +0530 Subject: [PATCH 01/33] removed some dead code --- packages/Webkul/Checkout/src/Cart.php | 53 ------------------- .../src/Http/Controllers/CartController.php | 8 --- packages/Webkul/Shop/src/Http/routes.php | 2 - .../views/checkout/onepage.blade.php | 16 +++++- 4 files changed, 15 insertions(+), 64 deletions(-) diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index 98087c8be..bd147d87f 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -1092,59 +1092,6 @@ class Cart { return $finalData; } - /** - * Save discount data for cart - */ - public function saveDiscount() - { - $rule = $impact['rule']; - - $cart = $this->getCart(); - - //update the cart items - foreach($cart->items as $item) { - if ($rule->use_coupon) { - if ($rule->action_type != config('pricerules.cart.validation.0')) { - $item->update([ - 'coupon_code' => $rule->coupon->code, - 'discount_amount' => core()->convertPrice($impact['amount'], $cart->channel_currency_code), - 'base_discount_amount' => $impact['amount'] - ]); - } else { - $item->update([ - 'coupon_code' => $rule->coupon->code, - 'discount_percent' => $rule->disc_amount - ]); - } - } else { - if ($rule->action_type != config('pricerules.cart.validation.0')) { - $item->update([ - 'discount_amount' => core()->convertPrice($impact['amount'], $cart->channel_currency_code), - 'base_discount_amount' => $impact['amount'] - ]); - } else { - $item->update([ - 'discount_percent' => $rule->disc_amount - ]); - } - } - } - - // update the cart - if ($rule->use_coupon) { - $cart->update([ - 'coupon_code' => $rule->coupons->code, - 'discount_amount' => core()->convertPrice($impact['amount'], $cart->channel_currency_code), - 'base_discount_amount' => $impact['amount'] - ]); - } else { - $cart->update([ - 'discount_amount' => core()->convertPrice($impact['amount'], $cart->channel_currency_code), - 'base_discount_amount' => $impact['amount'] - ]); - } - } - /** * Prepares data for order item * diff --git a/packages/Webkul/Shop/src/Http/Controllers/CartController.php b/packages/Webkul/Shop/src/Http/Controllers/CartController.php index 77ad39612..e163b30c2 100755 --- a/packages/Webkul/Shop/src/Http/Controllers/CartController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/CartController.php @@ -280,14 +280,6 @@ class CartController extends Controller return $nonCouponAbleRules; } - /** - * To save the discount values inside the tables of orders and cart - */ - public function saveDiscount() - { - return ['hellow']; - } - /** * To remove the currently active * couponable rule diff --git a/packages/Webkul/Shop/src/Http/routes.php b/packages/Webkul/Shop/src/Http/routes.php index 72a89ec52..ac485a2c9 100755 --- a/packages/Webkul/Shop/src/Http/routes.php +++ b/packages/Webkul/Shop/src/Http/routes.php @@ -41,8 +41,6 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function Route::post('checkout/check/coupons', 'Webkul\Shop\Http\Controllers\CartController@applyCoupon')->name('shop.checkout.check.coupons'); - Route::post('checkout/save/discounts', 'Webkul\Shop\Http\Controllers\CartController@saveDiscount')->name('shop.checkout.save.discount'); - Route::post('checkout/fetch/noncoupon', 'Webkul\Shop\Http\Controllers\CartController@getNonCouponAbleRule')->name('shop.checkout.fetch.non-coupon'); Route::post('checkout/remove/coupon', 'Webkul\Shop\Http\Controllers\CartController@removeCoupon')->name('shop.checkout.remove.coupon'); diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php index a2d7294fb..d9b240710 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -342,7 +342,7 @@ }) var summaryTemplateRenderFns = []; - + Vue.component('summary-section', { inject: ['$validator'], @@ -504,6 +504,20 @@ this.templateRender() : '') ]); + }, + + methods: { + onSubmit: function() { + var this_this = this; + + axios.post('{{ route('shop.checkout.check.coupons') }}', { + code: this_this.code + }).then(function(response) { + console.log(response.data); + }).catch(function(error) { + console.log(error.data); + }); + } } }); From 1e865986c4712255d49005aee1be0a85e95691e3 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Fri, 14 Jun 2019 19:24:15 +0530 Subject: [PATCH 02/33] improved conditions check in applying cart rules --- packages/Webkul/Admin/src/Http/routes.php | 2 +- .../Admin/src/Resources/lang/en/app.php | 2 +- packages/Webkul/Checkout/src/Cart.php | 10 ++++---- .../Webkul/Discount/src/Helpers/Discount.php | 12 ++++++++++ packages/Webkul/Shop/src/Http/routes.php | 2 -- .../views/checkout/onepage.blade.php | 24 ++++++++++++++++++- .../views/checkout/total/summary.blade.php | 2 +- 7 files changed, 43 insertions(+), 11 deletions(-) diff --git a/packages/Webkul/Admin/src/Http/routes.php b/packages/Webkul/Admin/src/Http/routes.php index c9de0b06d..13428def2 100755 --- a/packages/Webkul/Admin/src/Http/routes.php +++ b/packages/Webkul/Admin/src/Http/routes.php @@ -649,7 +649,7 @@ Route::group(['middleware' => ['web']], function () { // Route::post('fetch/options', 'Webkul\Discount\Http\Controllers\CatalogRuleController@fetchAttributeOptions')->name('admin.catalog-rule.options'); - Route::get('/cart-rule', 'Webkul\Discount\Http\Controllers\CartRuleController@index')->defaults('_config', [ + Route::get('/cart-rules', 'Webkul\Discount\Http\Controllers\CartRuleController@index')->defaults('_config', [ 'view' => 'admin::promotions.cart-rule.index' ])->name('admin.cart-rule.index'); diff --git a/packages/Webkul/Admin/src/Resources/lang/en/app.php b/packages/Webkul/Admin/src/Resources/lang/en/app.php index f1f99b62f..182256147 100755 --- a/packages/Webkul/Admin/src/Resources/lang/en/app.php +++ b/packages/Webkul/Admin/src/Resources/lang/en/app.php @@ -799,7 +799,7 @@ return [ 'promotion' => [ 'catalog-rule' => 'Catalog Rules', - 'cart-rule' => 'Cart Rule', + 'cart-rule' => 'Cart Rules', 'add-catalog-rule' => 'Add Catalog Rule', 'add-cart-rule' => 'Add Cart Rule', 'edit-cart-rule' => 'Edit Cart Rule', diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index bd147d87f..6bdbbffad 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -1277,12 +1277,12 @@ class Cart { return true; } - // public function removeCoupon() - // { - // $result = $this->discount->removeCoupon(); + public function removeCoupon() + { + $result = $this->discount->removeCoupon(); - // return $result; - // } + return $result; + } public function leastWorthItem() { diff --git a/packages/Webkul/Discount/src/Helpers/Discount.php b/packages/Webkul/Discount/src/Helpers/Discount.php index e033433af..95296b841 100644 --- a/packages/Webkul/Discount/src/Helpers/Discount.php +++ b/packages/Webkul/Discount/src/Helpers/Discount.php @@ -369,10 +369,22 @@ class Discount if ($cart->items_qty >= $disc_threshold && $realQty >= $disc_quantity) { if ($action_type == config('pricerules.cart.validation.0')) { $amountDiscounted = $leastWorthItem['total'] * ($disc_amount / 100); + + if ($amountDiscounted > $leastWorthItem['total']) { + $amountDiscounted = $leastWorthItem['total']; + } } else if ($action_type == config('pricerules.cart.validation.1')) { $amountDiscounted = $disc_amount; + + if ($amountDiscounted > $leastWorthItem['total']) { + $amountDiscounted = $leastWorthItem['total']; + } } else if ($action_type == config('pricerules.cart.validation.2')) { $amountDiscounted = $disc_amount; + + if ($amountDiscounted > $leastWorthItem['total']) { + $amountDiscounted = $leastWorthItem['total']; + } } } diff --git a/packages/Webkul/Shop/src/Http/routes.php b/packages/Webkul/Shop/src/Http/routes.php index ac485a2c9..ac044d289 100755 --- a/packages/Webkul/Shop/src/Http/routes.php +++ b/packages/Webkul/Shop/src/Http/routes.php @@ -41,8 +41,6 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function Route::post('checkout/check/coupons', 'Webkul\Shop\Http\Controllers\CartController@applyCoupon')->name('shop.checkout.check.coupons'); - Route::post('checkout/fetch/noncoupon', 'Webkul\Shop\Http\Controllers\CartController@getNonCouponAbleRule')->name('shop.checkout.fetch.non-coupon'); - Route::post('checkout/remove/coupon', 'Webkul\Shop\Http\Controllers\CartController@removeCoupon')->name('shop.checkout.remove.coupon'); //Cart Items Add diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php index d9b240710..5fcde8616 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -388,6 +388,17 @@ console.log(error.data); }); }, + + removeCoupon: function () { + var this_this = this; + + axios.post('{{ route('shop.checkout.remove.coupon') }}') + .then(function(response) { + console.log(response.data); + }).catch(function(error) { + console.log(error.data); + }); + } } }) @@ -507,7 +518,7 @@ }, methods: { - onSubmit: function() { + onSubmit: function () { var this_this = this; axios.post('{{ route('shop.checkout.check.coupons') }}', { @@ -517,6 +528,17 @@ }).catch(function(error) { console.log(error.data); }); + }, + + removeCoupon: function () { + var this_this = this; + + axios.post('{{ route('shop.checkout.remove.coupon') }}') + .then(function(response) { + console.log(response.data); + }).catch(function(error) { + console.log(error.data); + }); } } }); diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php index 1ffa9f9c4..91bc1ea4c 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php @@ -53,7 +53,7 @@
- +
@endif From bec9ebe7fbf3d7970dcf550122811ff5ee0794d1 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Fri, 14 Jun 2019 19:52:58 +0530 Subject: [PATCH 03/33] coupon section fix in review-order component --- .../Discount/src/Config/rule-conditions.php | 2 +- .../Webkul/Discount/src/Helpers/Discount.php | 39 ++++++++++--------- .../views/checkout/onepage.blade.php | 14 +++++-- .../views/checkout/total/summary.blade.php | 8 ++-- 4 files changed, 37 insertions(+), 26 deletions(-) diff --git a/packages/Webkul/Discount/src/Config/rule-conditions.php b/packages/Webkul/Discount/src/Config/rule-conditions.php index 7719a72ab..974bc5e3b 100644 --- a/packages/Webkul/Discount/src/Config/rule-conditions.php +++ b/packages/Webkul/Discount/src/Config/rule-conditions.php @@ -75,7 +75,7 @@ return [ 0 => 'percent_of_product', 1 => 'fixed_amount', 2 => 'buy_a_get_b', - 3 => 'fixed_amount_cart' + // 3 => 'fixed_amount_cart' ], 'conditions' => [ diff --git a/packages/Webkul/Discount/src/Helpers/Discount.php b/packages/Webkul/Discount/src/Helpers/Discount.php index 95296b841..0c35342a2 100644 --- a/packages/Webkul/Discount/src/Helpers/Discount.php +++ b/packages/Webkul/Discount/src/Helpers/Discount.php @@ -435,25 +435,10 @@ class Discount } /** - * Removes the cart rule from the cart + * Removes the couponable rule from the current cart and cart rule cart + * + * @return boolean */ - public function removeRule() - { - $cart = Cart::getCart(); - - $appliedRule = $this->cartRuleCart->findWhere([ - 'cart_id' => $cart->id - ]); - - if ($appliedRule->count() == 0) { - Cart::clearDiscount(); - - Cart::collectTotals(); - } - - return true; - } - public function removeCoupon() { $cart = \Cart::getCart(); @@ -464,6 +449,24 @@ class Discount if ($existingRule->count()) { if ($existingRule->first()->delete()) { + + foreach ($cart->items as $item) { + if ($item->discount_amount > 0) { + $item->update([ + 'discount_amount' => 0, + 'base_discount_amount' => 0, + 'discount_percent' => 0, + 'coupon_code' => NULL + ]); + } + } + + $cart->update([ + 'coupon_code' => NULL, + 'discount_amount' => 0, + 'base_discount_amount' => 0 + ]); + return true; } else { return false; diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php index 5fcde8616..1bbd17ad1 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -496,7 +496,9 @@ code: '', - hide_discount: 1 + hide_discount: 1, + + coupon_used: false } }, @@ -507,6 +509,11 @@ for (var i in reviewHtml.staticRenderFns) { reviewTemplateRenderFns.push(reviewHtml.staticRenderFns[i]); } + + @if ($cart->coupon_code != null) + this.code = '{{ $cart->coupon_code }}'; + this.coupon_used = true; + @endif }, render: function(h) { @@ -524,7 +531,8 @@ axios.post('{{ route('shop.checkout.check.coupons') }}', { code: this_this.code }).then(function(response) { - console.log(response.data); + this_this.coupon_used = true; + this_this.code = ''; }).catch(function(error) { console.log(error.data); }); @@ -535,7 +543,7 @@ axios.post('{{ route('shop.checkout.remove.coupon') }}') .then(function(response) { - console.log(response.data); + this_this.coupon_used = false; }).catch(function(error) { console.log(error.data); }); diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php index 91bc1ea4c..a3404acc9 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php @@ -37,9 +37,9 @@
- @if (! request()->is('checkout/cart') && ! $cart->coupon_code) + @if (! request()->is('checkout/cart'))
-
+
@@ -49,8 +49,8 @@
- @else -
+ +
From bb097be5576035ce17de29c141332793d05ce00e Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Fri, 14 Jun 2019 19:58:25 +0530 Subject: [PATCH 04/33] Added error message provision in the same when coupon application fails --- packages/Webkul/Shop/src/Resources/lang/en/app.php | 3 ++- .../Shop/src/Resources/views/checkout/onepage.blade.php | 8 +++++--- .../src/Resources/views/checkout/total/summary.blade.php | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/Webkul/Shop/src/Resources/lang/en/app.php b/packages/Webkul/Shop/src/Resources/lang/en/app.php index f27568335..2834e22c7 100755 --- a/packages/Webkul/Shop/src/Resources/lang/en/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/en/app.php @@ -456,7 +456,8 @@ return [ 'new-grand-total' => 'New Grand Total', 'coupon' => 'Coupon', 'coupon-applied' => 'Coupon Applied', - 'remove-coupon' => 'Remove Coupon' + 'remove-coupon' => 'Remove Coupon', + 'cannot-apply-coupon' => 'Cannot Apply Coupon' ], 'success' => [ diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php index 1bbd17ad1..8d1e37478 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -498,7 +498,9 @@ hide_discount: 1, - coupon_used: false + coupon_used: false, + + error_message = '' } }, @@ -532,9 +534,8 @@ code: this_this.code }).then(function(response) { this_this.coupon_used = true; - this_this.code = ''; }).catch(function(error) { - console.log(error.data); + this_this.error_message = '{{ __('shop::app.onepage.total.cannot-apply-coupon') }}' }); }, @@ -544,6 +545,7 @@ axios.post('{{ route('shop.checkout.remove.coupon') }}') .then(function(response) { this_this.coupon_used = false; + this_this.code = ''; }).catch(function(error) { console.log(error.data); }); diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php index a3404acc9..8bee0fe2e 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php @@ -45,6 +45,8 @@
+ @{{ error_message }} +
From 0188644fcedc6ef5af358f1985b279b515147054 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Fri, 14 Jun 2019 20:04:32 +0530 Subject: [PATCH 05/33] Prepared standard responses when applying couponable rules --- packages/Webkul/Discount/src/Helpers/Discount.php | 12 +++++++++++- .../Shop/src/Http/Controllers/CartController.php | 13 +++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/Webkul/Discount/src/Helpers/Discount.php b/packages/Webkul/Discount/src/Helpers/Discount.php index 0c35342a2..a1d8b0b05 100644 --- a/packages/Webkul/Discount/src/Helpers/Discount.php +++ b/packages/Webkul/Discount/src/Helpers/Discount.php @@ -36,6 +36,11 @@ class Discount $this->cartRuleCart = $cartRuleCart; } + /** + * Applies the non couponable rule on the current cart + * + * @return mixed + */ public function applyNonCouponAbleRule() { $cart = \Cart::getCart(); @@ -162,6 +167,11 @@ class Discount } } + /** + * Applies the couponable rule on the current cart + * + * @return mixed + */ public function applyCouponAbleRule($code) { $cart = \Cart::getCart(); @@ -314,7 +324,7 @@ class Discount } /** - * This function checks whether the rule is getting applied on the current cart or noy + * This function checks whether the rule is getting applied on the current cart or not * * @return mixed */ diff --git a/packages/Webkul/Shop/src/Http/Controllers/CartController.php b/packages/Webkul/Shop/src/Http/Controllers/CartController.php index e163b30c2..f3ec0a27c 100755 --- a/packages/Webkul/Shop/src/Http/Controllers/CartController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/CartController.php @@ -266,6 +266,19 @@ class CartController extends Controller $result = Cart::applyCoupon($code); + if ($result != null) { + return response()->json([ + 'success' => true, + 'message' => trans('shop::app.onepage.total.coupon-applied'), + 'result' => $result + ]); + } else { + return response()->json([ + 'success' => false, + 'message' => trans('shop::app.onepage.total.cannot-apply-coupon'), + 'result' => null + ]); + } return $result; } From c36950c609a830f061f5c0482cb415cf6244d7fc Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Fri, 14 Jun 2019 20:26:54 +0530 Subject: [PATCH 06/33] applied translation string in apply coupon responses --- .../Webkul/Shop/src/Http/Controllers/CartController.php | 5 +++-- .../Shop/src/Resources/views/checkout/onepage.blade.php | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/Webkul/Shop/src/Http/Controllers/CartController.php b/packages/Webkul/Shop/src/Http/Controllers/CartController.php index f3ec0a27c..274e1939c 100755 --- a/packages/Webkul/Shop/src/Http/Controllers/CartController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/CartController.php @@ -269,16 +269,17 @@ class CartController extends Controller if ($result != null) { return response()->json([ 'success' => true, - 'message' => trans('shop::app.onepage.total.coupon-applied'), + 'message' => trans('shop::app.checkout.onepage.total.coupon-applied'), 'result' => $result ]); } else { return response()->json([ 'success' => false, - 'message' => trans('shop::app.onepage.total.cannot-apply-coupon'), + 'message' => trans('shop::app.checkout.onepage.total.cannot-apply-coupon'), 'result' => null ]); } + return $result; } diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php index 8d1e37478..f59622a04 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -500,7 +500,7 @@ coupon_used: false, - error_message = '' + error_message: '' } }, @@ -534,8 +534,9 @@ code: this_this.code }).then(function(response) { this_this.coupon_used = true; + this_this.code = ''; }).catch(function(error) { - this_this.error_message = '{{ __('shop::app.onepage.total.cannot-apply-coupon') }}' + console.log(error.data); }); }, @@ -545,9 +546,10 @@ axios.post('{{ route('shop.checkout.remove.coupon') }}') .then(function(response) { this_this.coupon_used = false; - this_this.code = ''; }).catch(function(error) { console.log(error.data); + + this_this.error_message = '{{ __('shop::app.checkout.onepage.total.cannot-apply-coupon') }}' }); } } From 3a8b923f5c2d5c65a36aa45e5a63a79dfe1e8046 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Fri, 14 Jun 2019 23:48:08 +0530 Subject: [PATCH 07/33] Discount rule --- .../Webkul/Discount/src/Helpers/Discount.php | 4 +-- .../views/checkout/onepage.blade.php | 10 +++++-- .../views/checkout/total/summary.blade.php | 26 ++++++++++++------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/packages/Webkul/Discount/src/Helpers/Discount.php b/packages/Webkul/Discount/src/Helpers/Discount.php index a1d8b0b05..cee384b68 100644 --- a/packages/Webkul/Discount/src/Helpers/Discount.php +++ b/packages/Webkul/Discount/src/Helpers/Discount.php @@ -403,8 +403,8 @@ class Discount $report['discount'] = $amountDiscounted; $report['action'] = $action_type; $report['formatted_discount'] = core()->formatPrice($amountDiscounted, $cart->cart_currency_code); - $report['new_grand_total'] = $cart->grand_total - $amountDiscounted; - $report['formatted_new_grand_total'] = core()->formatPrice($cart->grand_total - $amountDiscounted, $cart->cart_currency_code); + $report['grand_total'] = $cart->grand_total - $amountDiscounted; + $report['formatted_grand_total'] = core()->formatPrice($cart->grand_total - $amountDiscounted, $cart->cart_currency_code); $report['priority'] = $rule->priority; return $report; diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php index f59622a04..071dbf16b 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -72,7 +72,7 @@
- +
@endif - @if ($cart->discount_amount && $cart->discount_amount > 0) -
- - -
- @endif -
+
discount_amount && $cart->discount_amount > 0) style="display: block;" @else style="display: none;" @endif> + + +
+ + +
- +
@@ -55,7 +63,7 @@
- +
@endif From 8d68be8e0746d29f89fa89d368adde5775f9e804 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Sat, 15 Jun 2019 12:27:54 +0530 Subject: [PATCH 08/33] Rule condition discount calculation now working properly --- packages/Webkul/Checkout/src/Cart.php | 3 +- ...19_05_13_024326_create_cart_rule_table.php | 4 +-- .../Webkul/Discount/src/Helpers/Discount.php | 28 +++++++++++++------ 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index 6bdbbffad..fc42a4823 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -1297,7 +1297,8 @@ class Cart { 'id' => $item->id, 'total' => $item->total, 'base_total' => $leastValue, - 'quantity' => $item->quantity + 'quantity' => $item->quantity, + 'price' => $item->price ]; } } diff --git a/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024326_create_cart_rule_table.php b/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024326_create_cart_rule_table.php index 03f6273ec..41859725a 100644 --- a/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024326_create_cart_rule_table.php +++ b/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024326_create_cart_rule_table.php @@ -39,8 +39,8 @@ class CreateCartRuleTable extends Migration $table->integer('sort_order')->unsigned()->default(0); $table->string('action_type')->nullable(); $table->decimal('disc_amount', 12, 4)->default(0); - $table->decimal('disc_quantity', 12, 4)->default(0); - $table->string('disc_threshold')->default(0); + $table->decimal('disc_quantity', 12, 4)->default(1); + $table->string('disc_threshold')->default(1); $table->integer('coupon_type')->default(1); $table->boolean('auto_generation')->default(0); $table->boolean('apply_to_shipping')->default(0); diff --git a/packages/Webkul/Discount/src/Helpers/Discount.php b/packages/Webkul/Discount/src/Helpers/Discount.php index cee384b68..f4938a557 100644 --- a/packages/Webkul/Discount/src/Helpers/Discount.php +++ b/packages/Webkul/Discount/src/Helpers/Discount.php @@ -376,24 +376,36 @@ class Discount $leastWorthItem = \Cart::leastWorthItem(); $realQty = $leastWorthItem['quantity']; - if ($cart->items_qty >= $disc_threshold && $realQty >= $disc_quantity) { + if ($cart->items_qty >= $disc_threshold) { if ($action_type == config('pricerules.cart.validation.0')) { - $amountDiscounted = $leastWorthItem['total'] * ($disc_amount / 100); + $amountDiscounted = $leastWorthItem['price'] * ($disc_amount / 100); - if ($amountDiscounted > $leastWorthItem['total']) { - $amountDiscounted = $leastWorthItem['total']; + if ($realQty > $disc_quantity) { + $amountDiscounted = $amountDiscounted * $disc_quantity; + } + + if ($amountDiscounted > $leastWorthItem['price']) { + $amountDiscounted = $leastWorthItem['price']; } } else if ($action_type == config('pricerules.cart.validation.1')) { $amountDiscounted = $disc_amount; - if ($amountDiscounted > $leastWorthItem['total']) { - $amountDiscounted = $leastWorthItem['total']; + if ($realQty > $disc_quantity) { + $amountDiscounted = $amountDiscounted * $disc_quantity; + } + + if ($amountDiscounted > $leastWorthItem['price']) { + $amountDiscounted = $leastWorthItem['price']; } } else if ($action_type == config('pricerules.cart.validation.2')) { $amountDiscounted = $disc_amount; - if ($amountDiscounted > $leastWorthItem['total']) { - $amountDiscounted = $leastWorthItem['total']; + if ($realQty > $disc_quantity) { + $amountDiscounted = $amountDiscounted * $disc_quantity; + } + + if ($amountDiscounted > $leastWorthItem['price']) { + $amountDiscounted = $leastWorthItem['price']; } } } From eaa755bbeae8115f255a4575bbe4d151b482f82b Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Sat, 15 Jun 2019 13:13:07 +0530 Subject: [PATCH 09/33] Fixed discount on frontend --- packages/Webkul/Discount/src/Helpers/Discount.php | 5 ++++- .../Webkul/Shop/src/Http/Controllers/CartController.php | 8 ++++++-- .../Shop/src/Resources/views/checkout/onepage.blade.php | 8 +++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/Webkul/Discount/src/Helpers/Discount.php b/packages/Webkul/Discount/src/Helpers/Discount.php index f4938a557..f48e14796 100644 --- a/packages/Webkul/Discount/src/Helpers/Discount.php +++ b/packages/Webkul/Discount/src/Helpers/Discount.php @@ -310,6 +310,8 @@ class Discount \Cart::collectTotals(); + $report['grand_total'] = core()->currency(\Cart::getCart()->grand_total); + break; } } @@ -471,7 +473,6 @@ class Discount if ($existingRule->count()) { if ($existingRule->first()->delete()) { - foreach ($cart->items as $item) { if ($item->discount_amount > 0) { $item->update([ @@ -489,6 +490,8 @@ class Discount 'base_discount_amount' => 0 ]); + \Cart::collectTotals(); + return true; } else { return false; diff --git a/packages/Webkul/Shop/src/Http/Controllers/CartController.php b/packages/Webkul/Shop/src/Http/Controllers/CartController.php index 274e1939c..48ffb82bf 100755 --- a/packages/Webkul/Shop/src/Http/Controllers/CartController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/CartController.php @@ -305,12 +305,16 @@ class CartController extends Controller if ($result) { return response()->json([ 'success' => true, - 'message' => trans('admin::app.promotion.status.coupon-removed') + 'message' => trans('admin::app.promotion.status.coupon-removed'), + 'data' => [ + 'grand_total' => core()->currency(Cart::getCart()->grand_total) + ] ]); } else { return response()->json([ 'success' => false, - 'message' => trans('admin::app.promotion.status.coupon-remove-failed') + 'message' => trans('admin::app.promotion.status.coupon-remove-failed'), + 'data' => null ]); } } diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php index 071dbf16b..607d84292 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -538,7 +538,7 @@ document.getElementById("discount-detail").style.display = "block"; document.getElementById("discount-detail-discount-amount").innerHTML = response.data.result.formatted_discount; - document.getElementById("discount-detail-discount-amount").innerHTML = response.data.result.formatted_discount; + document.getElementById("grand-total-amount-detail").innerHTML = response.data.result.grand_total; }).catch(function(error) { console.log(error.data); }); @@ -550,8 +550,14 @@ axios.post('{{ route('shop.checkout.remove.coupon') }}') .then(function(response) { this_this.coupon_used = false; + this_this.code = ''; + + console.log(response.data.data.grand_total); + document.getElementById("discount-detail").style.display = "none"; + + document.getElementById("grand-total-amount-detail").innerHTML = response.data.data.grand_total; }).catch(function(error) { console.log(error.data); From 0927786cee25a0ffd46c8268bc4e3041d2200885 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Sat, 15 Jun 2019 14:56:24 +0530 Subject: [PATCH 10/33] Fixed issue with order summary rendering on cart page --- .../promotions/cart-rule/create.blade.php | 4 +- .../Http/Controllers/CartRuleController.php | 69 ++++++++++++++----- .../views/checkout/total/summary.blade.php | 2 +- 3 files changed, 53 insertions(+), 22 deletions(-) diff --git a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php index 64c897335..0f2d6d222 100644 --- a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php @@ -74,7 +74,7 @@
- {{--
+
@{{ errors.first('customer_groups') }} -
--}} +
diff --git a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php index 807875db1..93f1271bf 100644 --- a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php +++ b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php @@ -83,12 +83,10 @@ class CartRuleController extends Controller */ public function store() { - $data = request()->all(); - $validated = $this->validate($data, [ 'name' => 'required|string', 'description' => 'string', - // 'customer_groups' => 'required|array', + 'customer_groups' => 'required|array', 'channels' => 'required|array', 'status' => 'required|boolean', 'use_coupon' => 'boolean|required', @@ -105,32 +103,45 @@ class CartRuleController extends Controller 'label' => 'array|nullable' ]); - $data = [ - 'usage_limit' => 0, - 'per_customer' => 0 - ]; + $data = request()->all(); + // unset token + unset($data['_token']); + + // set usage limit + $data['usage_limit'] = 0; + + // set per customer usage limit + $data['per_customer'] = 0; + + // check starts from and ends till if ($data['starts_from'] == "" || $data['ends_till'] == "") { $data['starts_from'] = null; $data['ends_till'] = null; } - unset($data['_token']); + // customer groups + $customer_groups = $data['customer_groups']; - $channels = $data['channels']; + // unset customer groups + unset($data['customer_groups']); - unset($data['channels']); - - // $customer_groups = $data['customer_groups']; - // unset($data['customer_groups']); + // unset criteria unset($data['criteria']); + // channels + $channels = $data['channels']; + + // unset channels + unset($data['channels']); + + // make labels $labels = $data['label']; + // unset labels unset($data['label']); - unset($data['cart_attributes']); - unset($data['attributes']); + // prepare json object from actions if (isset($data['disc_amount']) && $data['action_type'] == config('pricerules.cart.validations.2')) { $data['actions'] = [ 'action_type' => $data['action_type'], @@ -147,22 +158,37 @@ class CartRuleController extends Controller ]; } + // prepare json object from conditions $data['actions'] = json_encode($data['actions']); + // check if all if (! isset($data['all_conditions']) || $data['all_conditions'] == "[]") { $data['conditions'] = null; } else { $data['conditions'] = json_encode($data['all_conditions']); } + // unset cart_attributes from conditions + unset($data['cart_attributes']); + + // unset attributes from conditions + unset($data['attributes']); + + // unset all_conditions from conditions unset($data['all_conditions']); + // prepare coupons if coupons are used if ($data['use_coupon']) { // if (isset($data['auto_generation']) && $data['auto_generation']) { + // auto generation is off for now $data['auto_generation'] = 0; + // save the coupon used in coupon section $coupons['code'] = $data['code']; + // set coupon usage per customer same as per_customer limit which is disabled for now + $coupons['usage_per_customer'] = $data['per_customer']; //0 is for unlimited usage + // unset coupon code from coupon section unset($data['code']); // } else { // $data['auto_generation'] = 1; @@ -181,15 +207,21 @@ class CartRuleController extends Controller // $coupons['limit'] = 0; } + // per coupon usage limit // if(isset($data['usage_limit'])) { // $coupons['limit'] = $data['usage_limit']; // } + // create a cart rule $ruleCreated = $this->cartRule->create($data); - // $ruleGroupCreated = $this->cartRule->CustomerGroupSync($customer_groups, $ruleCreated); + // create customer groups for cart rule + $ruleGroupCreated = $this->cartRule->CustomerGroupSync($customer_groups, $ruleCreated); + + // create customer groups for channels $ruleChannelCreated = $this->cartRule->ChannelSync($channels, $ruleCreated); + // prepare labels if (isset($labels['global'])) { foreach (core()->getAllChannels() as $channel) { $label1['channel_id'] = $channel->id; @@ -209,14 +241,13 @@ class CartRuleController extends Controller $ruleLabelCreated = $this->cartRuleLabel->create($label2); } + // create coupon if present if (isset($coupons)) { $coupons['cart_rule_id'] = $ruleCreated->id; - $coupons['usage_per_customer'] = $data['per_customer']; //0 is for unlimited usage - $couponCreated = $this->cartRuleCoupon->create($coupons); } - if ($ruleCreated && $ruleChannelCreated) { + if ($ruleCreated && $ruleChannelCreated && $ruleGroupCreated) { if (isset($couponCreated) && $couponCreated) { session()->flash('success', trans('admin::app.promotion.status.success-coupon')); } diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php index 151dad9aa..ca2ebabfd 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php @@ -44,7 +44,7 @@
-
+
is('checkout/cart')) v-if="hide_discount" @endif> @if (! request()->is('checkout/cart'))
From 7ac715e93d7478afdebfe5b52a4c1f452238278e Mon Sep 17 00:00:00 2001 From: Jitendra Singh <39991107+jitendra-webkul@users.noreply.github.com> Date: Sat, 15 Jun 2019 15:09:59 +0530 Subject: [PATCH 11/33] Revert "Fixed issue with order summary rendering on cart page" --- .../promotions/cart-rule/create.blade.php | 4 +- .../Http/Controllers/CartRuleController.php | 67 +++++-------------- .../views/checkout/total/summary.blade.php | 2 +- 3 files changed, 21 insertions(+), 52 deletions(-) diff --git a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php index 0f2d6d222..64c897335 100644 --- a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php @@ -74,7 +74,7 @@
-
+ {{--
@{{ errors.first('customer_groups') }} -
+
--}}
diff --git a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php index 93f1271bf..807875db1 100644 --- a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php +++ b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php @@ -83,10 +83,12 @@ class CartRuleController extends Controller */ public function store() { + $data = request()->all(); + $validated = $this->validate($data, [ 'name' => 'required|string', 'description' => 'string', - 'customer_groups' => 'required|array', + // 'customer_groups' => 'required|array', 'channels' => 'required|array', 'status' => 'required|boolean', 'use_coupon' => 'boolean|required', @@ -103,45 +105,32 @@ class CartRuleController extends Controller 'label' => 'array|nullable' ]); - $data = request()->all(); + $data = [ + 'usage_limit' => 0, + 'per_customer' => 0 + ]; - // unset token - unset($data['_token']); - - // set usage limit - $data['usage_limit'] = 0; - - // set per customer usage limit - $data['per_customer'] = 0; - - // check starts from and ends till if ($data['starts_from'] == "" || $data['ends_till'] == "") { $data['starts_from'] = null; $data['ends_till'] = null; } - // customer groups - $customer_groups = $data['customer_groups']; + unset($data['_token']); - // unset customer groups - unset($data['customer_groups']); - - // unset criteria - unset($data['criteria']); - - // channels $channels = $data['channels']; - // unset channels unset($data['channels']); - // make labels + // $customer_groups = $data['customer_groups']; + // unset($data['customer_groups']); + unset($data['criteria']); + $labels = $data['label']; - // unset labels unset($data['label']); + unset($data['cart_attributes']); + unset($data['attributes']); - // prepare json object from actions if (isset($data['disc_amount']) && $data['action_type'] == config('pricerules.cart.validations.2')) { $data['actions'] = [ 'action_type' => $data['action_type'], @@ -158,37 +147,22 @@ class CartRuleController extends Controller ]; } - // prepare json object from conditions $data['actions'] = json_encode($data['actions']); - // check if all if (! isset($data['all_conditions']) || $data['all_conditions'] == "[]") { $data['conditions'] = null; } else { $data['conditions'] = json_encode($data['all_conditions']); } - // unset cart_attributes from conditions - unset($data['cart_attributes']); - - // unset attributes from conditions - unset($data['attributes']); - - // unset all_conditions from conditions unset($data['all_conditions']); - // prepare coupons if coupons are used if ($data['use_coupon']) { // if (isset($data['auto_generation']) && $data['auto_generation']) { - // auto generation is off for now $data['auto_generation'] = 0; - // save the coupon used in coupon section $coupons['code'] = $data['code']; - // set coupon usage per customer same as per_customer limit which is disabled for now - $coupons['usage_per_customer'] = $data['per_customer']; //0 is for unlimited usage - // unset coupon code from coupon section unset($data['code']); // } else { // $data['auto_generation'] = 1; @@ -207,21 +181,15 @@ class CartRuleController extends Controller // $coupons['limit'] = 0; } - // per coupon usage limit // if(isset($data['usage_limit'])) { // $coupons['limit'] = $data['usage_limit']; // } - // create a cart rule $ruleCreated = $this->cartRule->create($data); - // create customer groups for cart rule - $ruleGroupCreated = $this->cartRule->CustomerGroupSync($customer_groups, $ruleCreated); - - // create customer groups for channels + // $ruleGroupCreated = $this->cartRule->CustomerGroupSync($customer_groups, $ruleCreated); $ruleChannelCreated = $this->cartRule->ChannelSync($channels, $ruleCreated); - // prepare labels if (isset($labels['global'])) { foreach (core()->getAllChannels() as $channel) { $label1['channel_id'] = $channel->id; @@ -241,13 +209,14 @@ class CartRuleController extends Controller $ruleLabelCreated = $this->cartRuleLabel->create($label2); } - // create coupon if present if (isset($coupons)) { $coupons['cart_rule_id'] = $ruleCreated->id; + $coupons['usage_per_customer'] = $data['per_customer']; //0 is for unlimited usage + $couponCreated = $this->cartRuleCoupon->create($coupons); } - if ($ruleCreated && $ruleChannelCreated && $ruleGroupCreated) { + if ($ruleCreated && $ruleChannelCreated) { if (isset($couponCreated) && $couponCreated) { session()->flash('success', trans('admin::app.promotion.status.success-coupon')); } diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php index ca2ebabfd..151dad9aa 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php @@ -44,7 +44,7 @@
-
is('checkout/cart')) v-if="hide_discount" @endif> +
@if (! request()->is('checkout/cart'))
From 668f92185bb0868bd5d1cbe61e30534af40d4fea Mon Sep 17 00:00:00 2001 From: Jitendra Singh <39991107+jitendra-webkul@users.noreply.github.com> Date: Sat, 15 Jun 2019 15:10:04 +0530 Subject: [PATCH 12/33] Revert "Development" --- packages/Webkul/Checkout/src/Cart.php | 3 +- ...19_05_13_024326_create_cart_rule_table.php | 4 +-- .../Webkul/Discount/src/Helpers/Discount.php | 33 +++++-------------- .../src/Http/Controllers/CartController.php | 8 ++--- .../views/checkout/onepage.blade.php | 8 +---- 5 files changed, 15 insertions(+), 41 deletions(-) diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index fc42a4823..6bdbbffad 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -1297,8 +1297,7 @@ class Cart { 'id' => $item->id, 'total' => $item->total, 'base_total' => $leastValue, - 'quantity' => $item->quantity, - 'price' => $item->price + 'quantity' => $item->quantity ]; } } diff --git a/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024326_create_cart_rule_table.php b/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024326_create_cart_rule_table.php index 41859725a..03f6273ec 100644 --- a/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024326_create_cart_rule_table.php +++ b/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024326_create_cart_rule_table.php @@ -39,8 +39,8 @@ class CreateCartRuleTable extends Migration $table->integer('sort_order')->unsigned()->default(0); $table->string('action_type')->nullable(); $table->decimal('disc_amount', 12, 4)->default(0); - $table->decimal('disc_quantity', 12, 4)->default(1); - $table->string('disc_threshold')->default(1); + $table->decimal('disc_quantity', 12, 4)->default(0); + $table->string('disc_threshold')->default(0); $table->integer('coupon_type')->default(1); $table->boolean('auto_generation')->default(0); $table->boolean('apply_to_shipping')->default(0); diff --git a/packages/Webkul/Discount/src/Helpers/Discount.php b/packages/Webkul/Discount/src/Helpers/Discount.php index f48e14796..cee384b68 100644 --- a/packages/Webkul/Discount/src/Helpers/Discount.php +++ b/packages/Webkul/Discount/src/Helpers/Discount.php @@ -310,8 +310,6 @@ class Discount \Cart::collectTotals(); - $report['grand_total'] = core()->currency(\Cart::getCart()->grand_total); - break; } } @@ -378,36 +376,24 @@ class Discount $leastWorthItem = \Cart::leastWorthItem(); $realQty = $leastWorthItem['quantity']; - if ($cart->items_qty >= $disc_threshold) { + if ($cart->items_qty >= $disc_threshold && $realQty >= $disc_quantity) { if ($action_type == config('pricerules.cart.validation.0')) { - $amountDiscounted = $leastWorthItem['price'] * ($disc_amount / 100); + $amountDiscounted = $leastWorthItem['total'] * ($disc_amount / 100); - if ($realQty > $disc_quantity) { - $amountDiscounted = $amountDiscounted * $disc_quantity; - } - - if ($amountDiscounted > $leastWorthItem['price']) { - $amountDiscounted = $leastWorthItem['price']; + if ($amountDiscounted > $leastWorthItem['total']) { + $amountDiscounted = $leastWorthItem['total']; } } else if ($action_type == config('pricerules.cart.validation.1')) { $amountDiscounted = $disc_amount; - if ($realQty > $disc_quantity) { - $amountDiscounted = $amountDiscounted * $disc_quantity; - } - - if ($amountDiscounted > $leastWorthItem['price']) { - $amountDiscounted = $leastWorthItem['price']; + if ($amountDiscounted > $leastWorthItem['total']) { + $amountDiscounted = $leastWorthItem['total']; } } else if ($action_type == config('pricerules.cart.validation.2')) { $amountDiscounted = $disc_amount; - if ($realQty > $disc_quantity) { - $amountDiscounted = $amountDiscounted * $disc_quantity; - } - - if ($amountDiscounted > $leastWorthItem['price']) { - $amountDiscounted = $leastWorthItem['price']; + if ($amountDiscounted > $leastWorthItem['total']) { + $amountDiscounted = $leastWorthItem['total']; } } } @@ -473,6 +459,7 @@ class Discount if ($existingRule->count()) { if ($existingRule->first()->delete()) { + foreach ($cart->items as $item) { if ($item->discount_amount > 0) { $item->update([ @@ -490,8 +477,6 @@ class Discount 'base_discount_amount' => 0 ]); - \Cart::collectTotals(); - return true; } else { return false; diff --git a/packages/Webkul/Shop/src/Http/Controllers/CartController.php b/packages/Webkul/Shop/src/Http/Controllers/CartController.php index 48ffb82bf..274e1939c 100755 --- a/packages/Webkul/Shop/src/Http/Controllers/CartController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/CartController.php @@ -305,16 +305,12 @@ class CartController extends Controller if ($result) { return response()->json([ 'success' => true, - 'message' => trans('admin::app.promotion.status.coupon-removed'), - 'data' => [ - 'grand_total' => core()->currency(Cart::getCart()->grand_total) - ] + 'message' => trans('admin::app.promotion.status.coupon-removed') ]); } else { return response()->json([ 'success' => false, - 'message' => trans('admin::app.promotion.status.coupon-remove-failed'), - 'data' => null + 'message' => trans('admin::app.promotion.status.coupon-remove-failed') ]); } } diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php index 607d84292..071dbf16b 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -538,7 +538,7 @@ document.getElementById("discount-detail").style.display = "block"; document.getElementById("discount-detail-discount-amount").innerHTML = response.data.result.formatted_discount; - document.getElementById("grand-total-amount-detail").innerHTML = response.data.result.grand_total; + document.getElementById("discount-detail-discount-amount").innerHTML = response.data.result.formatted_discount; }).catch(function(error) { console.log(error.data); }); @@ -550,14 +550,8 @@ axios.post('{{ route('shop.checkout.remove.coupon') }}') .then(function(response) { this_this.coupon_used = false; - this_this.code = ''; - - console.log(response.data.data.grand_total); - document.getElementById("discount-detail").style.display = "none"; - - document.getElementById("grand-total-amount-detail").innerHTML = response.data.data.grand_total; }).catch(function(error) { console.log(error.data); From fb5687c451437d45333cabe6440ed48879943ad6 Mon Sep 17 00:00:00 2001 From: Jitendra Singh <39991107+jitendra-webkul@users.noreply.github.com> Date: Sat, 15 Jun 2019 15:10:10 +0530 Subject: [PATCH 13/33] Revert "buy now issue" --- .../src/Resources/views/products/view.blade.php | 13 +++++++++++++ .../products/view/configurable-options.blade.php | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/Webkul/Shop/src/Resources/views/products/view.blade.php b/packages/Webkul/Shop/src/Resources/views/products/view.blade.php index b2382da2e..16f53e156 100755 --- a/packages/Webkul/Shop/src/Resources/views/products/view.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/view.blade.php @@ -205,6 +205,19 @@ } document.getElementById("quantity").value = quantity; + var buyNowLink = $('.btn.buynow').attr('data-href'); + var splitted = buyNowLink.split("/"); + lastItem = splitted[splitted.length - 2]; + + splitted.pop(); + splitted.pop(); + + var joined = splitted.join('/'); + + var newBuyNowUrl = joined + '/' + lastItem + '/' + quantity; + + $('.btn.buynow').attr('data-href', newBuyNowUrl); + event.preventDefault(); } diff --git a/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php b/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php index a1d91cb2f..536f6a006 100755 --- a/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php @@ -148,13 +148,14 @@ if (this.selectedProductId != '' && buyNowLink) { var splitted = buyNowLink.split("/"); + splitted.pop(); splitted.pop(); lastItem = this.selectedProductId; var joined = splitted.join('/'); - var newBuyNowUrl = joined + '/' + lastItem; + var newBuyNowUrl = joined + '/' + lastItem + '/' + quantity; $('.btn.buynow').attr('data-href', newBuyNowUrl); } From 426cbe0ae5a7cf2edac31867cf49968252309c14 Mon Sep 17 00:00:00 2001 From: Jitendra Singh <39991107+jitendra-webkul@users.noreply.github.com> Date: Sat, 15 Jun 2019 15:10:11 +0530 Subject: [PATCH 14/33] Revert "Added Guest default customer group with id 0" --- .../src/Database/Seeders/CustomerGroupTableSeeder.php | 8 ++++---- .../2018_07_24_082635_create_customer_groups_table.php | 0 .../2018_07_24_082930_create_customers_table.php | 0 .../2018_07_24_083025_create_customer_addresses_table.php | 0 .../2018_09_11_064045_customer_password_resets.php | 0 .../2018_10_03_025230_create_wishlist_table.php | 0 ...7_165758_add_is_verified_column_in_customers_table.php | 0 ..._26_110500_change_gender_column_in_customers_table.php | 0 ...9_03_28_103658_add_notes_column_in_customers_table.php | 0 ...9_06_04_114009_add_phone_column_in_customers_table.php | 0 .../Customer/src/Providers/CustomerServiceProvider.php | 2 +- 11 files changed, 5 insertions(+), 5 deletions(-) rename packages/Webkul/Customer/src/Database/{Migrations => migrations}/2018_07_24_082635_create_customer_groups_table.php (100%) rename packages/Webkul/Customer/src/Database/{Migrations => migrations}/2018_07_24_082930_create_customers_table.php (100%) rename packages/Webkul/Customer/src/Database/{Migrations => migrations}/2018_07_24_083025_create_customer_addresses_table.php (100%) rename packages/Webkul/Customer/src/Database/{Migrations => migrations}/2018_09_11_064045_customer_password_resets.php (100%) rename packages/Webkul/Customer/src/Database/{Migrations => migrations}/2018_10_03_025230_create_wishlist_table.php (100%) rename packages/Webkul/Customer/src/Database/{Migrations => migrations}/2018_11_17_165758_add_is_verified_column_in_customers_table.php (100%) rename packages/Webkul/Customer/src/Database/{Migrations => migrations}/2018_11_26_110500_change_gender_column_in_customers_table.php (100%) rename packages/Webkul/Customer/src/Database/{Migrations => migrations}/2019_03_28_103658_add_notes_column_in_customers_table.php (100%) rename packages/Webkul/Customer/src/Database/{Migrations => migrations}/2019_06_04_114009_add_phone_column_in_customers_table.php (100%) diff --git a/packages/Webkul/Customer/src/Database/Seeders/CustomerGroupTableSeeder.php b/packages/Webkul/Customer/src/Database/Seeders/CustomerGroupTableSeeder.php index bbb66e3e8..6a83e7b4d 100755 --- a/packages/Webkul/Customer/src/Database/Seeders/CustomerGroupTableSeeder.php +++ b/packages/Webkul/Customer/src/Database/Seeders/CustomerGroupTableSeeder.php @@ -12,10 +12,6 @@ class CustomerGroupTableSeeder extends Seeder DB::table('customer_groups')->delete(); DB::table('customer_groups')->insert([ - 'id' => 0, - 'name' => 'Guest', - 'is_user_defined' => 0, - ], [ 'id' => 1, 'name' => 'General', 'is_user_defined' => 0, @@ -23,6 +19,10 @@ class CustomerGroupTableSeeder extends Seeder 'id' => 2, 'name' => 'Wholesale', 'is_user_defined' => 0, + ], [ + 'id' => 3, + 'name' => 'Not Logged In', + 'is_user_defined' => 0, ]); } } \ No newline at end of file diff --git a/packages/Webkul/Customer/src/Database/Migrations/2018_07_24_082635_create_customer_groups_table.php b/packages/Webkul/Customer/src/Database/migrations/2018_07_24_082635_create_customer_groups_table.php similarity index 100% rename from packages/Webkul/Customer/src/Database/Migrations/2018_07_24_082635_create_customer_groups_table.php rename to packages/Webkul/Customer/src/Database/migrations/2018_07_24_082635_create_customer_groups_table.php diff --git a/packages/Webkul/Customer/src/Database/Migrations/2018_07_24_082930_create_customers_table.php b/packages/Webkul/Customer/src/Database/migrations/2018_07_24_082930_create_customers_table.php similarity index 100% rename from packages/Webkul/Customer/src/Database/Migrations/2018_07_24_082930_create_customers_table.php rename to packages/Webkul/Customer/src/Database/migrations/2018_07_24_082930_create_customers_table.php diff --git a/packages/Webkul/Customer/src/Database/Migrations/2018_07_24_083025_create_customer_addresses_table.php b/packages/Webkul/Customer/src/Database/migrations/2018_07_24_083025_create_customer_addresses_table.php similarity index 100% rename from packages/Webkul/Customer/src/Database/Migrations/2018_07_24_083025_create_customer_addresses_table.php rename to packages/Webkul/Customer/src/Database/migrations/2018_07_24_083025_create_customer_addresses_table.php diff --git a/packages/Webkul/Customer/src/Database/Migrations/2018_09_11_064045_customer_password_resets.php b/packages/Webkul/Customer/src/Database/migrations/2018_09_11_064045_customer_password_resets.php similarity index 100% rename from packages/Webkul/Customer/src/Database/Migrations/2018_09_11_064045_customer_password_resets.php rename to packages/Webkul/Customer/src/Database/migrations/2018_09_11_064045_customer_password_resets.php 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 similarity index 100% rename from packages/Webkul/Customer/src/Database/Migrations/2018_10_03_025230_create_wishlist_table.php rename to packages/Webkul/Customer/src/Database/migrations/2018_10_03_025230_create_wishlist_table.php diff --git a/packages/Webkul/Customer/src/Database/Migrations/2018_11_17_165758_add_is_verified_column_in_customers_table.php b/packages/Webkul/Customer/src/Database/migrations/2018_11_17_165758_add_is_verified_column_in_customers_table.php similarity index 100% rename from packages/Webkul/Customer/src/Database/Migrations/2018_11_17_165758_add_is_verified_column_in_customers_table.php rename to packages/Webkul/Customer/src/Database/migrations/2018_11_17_165758_add_is_verified_column_in_customers_table.php diff --git a/packages/Webkul/Customer/src/Database/Migrations/2018_11_26_110500_change_gender_column_in_customers_table.php b/packages/Webkul/Customer/src/Database/migrations/2018_11_26_110500_change_gender_column_in_customers_table.php similarity index 100% rename from packages/Webkul/Customer/src/Database/Migrations/2018_11_26_110500_change_gender_column_in_customers_table.php rename to packages/Webkul/Customer/src/Database/migrations/2018_11_26_110500_change_gender_column_in_customers_table.php diff --git a/packages/Webkul/Customer/src/Database/Migrations/2019_03_28_103658_add_notes_column_in_customers_table.php b/packages/Webkul/Customer/src/Database/migrations/2019_03_28_103658_add_notes_column_in_customers_table.php similarity index 100% rename from packages/Webkul/Customer/src/Database/Migrations/2019_03_28_103658_add_notes_column_in_customers_table.php rename to packages/Webkul/Customer/src/Database/migrations/2019_03_28_103658_add_notes_column_in_customers_table.php diff --git a/packages/Webkul/Customer/src/Database/Migrations/2019_06_04_114009_add_phone_column_in_customers_table.php b/packages/Webkul/Customer/src/Database/migrations/2019_06_04_114009_add_phone_column_in_customers_table.php similarity index 100% rename from packages/Webkul/Customer/src/Database/Migrations/2019_06_04_114009_add_phone_column_in_customers_table.php rename to packages/Webkul/Customer/src/Database/migrations/2019_06_04_114009_add_phone_column_in_customers_table.php diff --git a/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php b/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php index 7311c808c..8ef088d13 100755 --- a/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php +++ b/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php @@ -14,6 +14,6 @@ class CustomerServiceProvider extends ServiceProvider $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'customer'); - $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); + $this->loadMigrationsFrom(__DIR__ . '/../Database/migrations'); } } From ff64d23319be3fa8e2857ddb4c0db9e387825a4b Mon Sep 17 00:00:00 2001 From: jitendra Date: Sat, 15 Jun 2019 16:34:56 +0530 Subject: [PATCH 15/33] Guest removed from customer pages --- .../src/Http/Controllers/Customer/CustomerController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/Webkul/Admin/src/Http/Controllers/Customer/CustomerController.php b/packages/Webkul/Admin/src/Http/Controllers/Customer/CustomerController.php index c2b700582..6f0e2dfa9 100755 --- a/packages/Webkul/Admin/src/Http/Controllers/Customer/CustomerController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Customer/CustomerController.php @@ -83,7 +83,7 @@ class CustomerController extends Controller */ public function create() { - $customerGroup = $this->customerGroup->all(); + $customerGroup = $this->customerGroup->findWhere([['id', '<>', 0]]); $channelName = $this->channel->all(); @@ -131,7 +131,7 @@ class CustomerController extends Controller { $customer = $this->customer->findOrFail($id); - $customerGroup = $this->customerGroup->all(); + $customerGroup = $this->customerGroup->findWhere([['id', '<>', 0]]); $channelName = $this->channel->all(); From e3946a79ddc9ff24f618acac610c0d67680689f5 Mon Sep 17 00:00:00 2001 From: jitendra Date: Sat, 15 Jun 2019 16:46:55 +0530 Subject: [PATCH 16/33] Reset changes --- .../Webkul/Customer/src/Http/Controllers/AccountController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/Webkul/Customer/src/Http/Controllers/AccountController.php b/packages/Webkul/Customer/src/Http/Controllers/AccountController.php index 446660570..1fb69057a 100755 --- a/packages/Webkul/Customer/src/Http/Controllers/AccountController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/AccountController.php @@ -17,7 +17,6 @@ use Auth; * @author Prashant Singh * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ - class AccountController extends Controller { /** From d4d9c3e5eeb3c55490ddea5a931ccb966e722b56 Mon Sep 17 00:00:00 2001 From: Jitendra Singh <39991107+jitendra-webkul@users.noreply.github.com> Date: Sat, 15 Jun 2019 16:48:29 +0530 Subject: [PATCH 17/33] Revert "Revert "Added Guest default customer group with id 0"" --- .../2018_07_24_082635_create_customer_groups_table.php | 0 .../2018_07_24_082930_create_customers_table.php | 0 .../2018_07_24_083025_create_customer_addresses_table.php | 0 .../2018_09_11_064045_customer_password_resets.php | 0 .../2018_10_03_025230_create_wishlist_table.php | 0 ...7_165758_add_is_verified_column_in_customers_table.php | 0 ..._26_110500_change_gender_column_in_customers_table.php | 0 ...9_03_28_103658_add_notes_column_in_customers_table.php | 0 ...9_06_04_114009_add_phone_column_in_customers_table.php | 0 .../src/Database/Seeders/CustomerGroupTableSeeder.php | 8 ++++---- .../Customer/src/Providers/CustomerServiceProvider.php | 2 +- 11 files changed, 5 insertions(+), 5 deletions(-) rename packages/Webkul/Customer/src/Database/{migrations => Migrations}/2018_07_24_082635_create_customer_groups_table.php (100%) rename packages/Webkul/Customer/src/Database/{migrations => Migrations}/2018_07_24_082930_create_customers_table.php (100%) rename packages/Webkul/Customer/src/Database/{migrations => Migrations}/2018_07_24_083025_create_customer_addresses_table.php (100%) rename packages/Webkul/Customer/src/Database/{migrations => Migrations}/2018_09_11_064045_customer_password_resets.php (100%) rename packages/Webkul/Customer/src/Database/{migrations => Migrations}/2018_10_03_025230_create_wishlist_table.php (100%) rename packages/Webkul/Customer/src/Database/{migrations => Migrations}/2018_11_17_165758_add_is_verified_column_in_customers_table.php (100%) rename packages/Webkul/Customer/src/Database/{migrations => Migrations}/2018_11_26_110500_change_gender_column_in_customers_table.php (100%) rename packages/Webkul/Customer/src/Database/{migrations => Migrations}/2019_03_28_103658_add_notes_column_in_customers_table.php (100%) rename packages/Webkul/Customer/src/Database/{migrations => Migrations}/2019_06_04_114009_add_phone_column_in_customers_table.php (100%) diff --git a/packages/Webkul/Customer/src/Database/migrations/2018_07_24_082635_create_customer_groups_table.php b/packages/Webkul/Customer/src/Database/Migrations/2018_07_24_082635_create_customer_groups_table.php similarity index 100% rename from packages/Webkul/Customer/src/Database/migrations/2018_07_24_082635_create_customer_groups_table.php rename to packages/Webkul/Customer/src/Database/Migrations/2018_07_24_082635_create_customer_groups_table.php diff --git a/packages/Webkul/Customer/src/Database/migrations/2018_07_24_082930_create_customers_table.php b/packages/Webkul/Customer/src/Database/Migrations/2018_07_24_082930_create_customers_table.php similarity index 100% rename from packages/Webkul/Customer/src/Database/migrations/2018_07_24_082930_create_customers_table.php rename to packages/Webkul/Customer/src/Database/Migrations/2018_07_24_082930_create_customers_table.php diff --git a/packages/Webkul/Customer/src/Database/migrations/2018_07_24_083025_create_customer_addresses_table.php b/packages/Webkul/Customer/src/Database/Migrations/2018_07_24_083025_create_customer_addresses_table.php similarity index 100% rename from packages/Webkul/Customer/src/Database/migrations/2018_07_24_083025_create_customer_addresses_table.php rename to packages/Webkul/Customer/src/Database/Migrations/2018_07_24_083025_create_customer_addresses_table.php diff --git a/packages/Webkul/Customer/src/Database/migrations/2018_09_11_064045_customer_password_resets.php b/packages/Webkul/Customer/src/Database/Migrations/2018_09_11_064045_customer_password_resets.php similarity index 100% rename from packages/Webkul/Customer/src/Database/migrations/2018_09_11_064045_customer_password_resets.php rename to packages/Webkul/Customer/src/Database/Migrations/2018_09_11_064045_customer_password_resets.php 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 similarity index 100% rename from packages/Webkul/Customer/src/Database/migrations/2018_10_03_025230_create_wishlist_table.php rename to packages/Webkul/Customer/src/Database/Migrations/2018_10_03_025230_create_wishlist_table.php diff --git a/packages/Webkul/Customer/src/Database/migrations/2018_11_17_165758_add_is_verified_column_in_customers_table.php b/packages/Webkul/Customer/src/Database/Migrations/2018_11_17_165758_add_is_verified_column_in_customers_table.php similarity index 100% rename from packages/Webkul/Customer/src/Database/migrations/2018_11_17_165758_add_is_verified_column_in_customers_table.php rename to packages/Webkul/Customer/src/Database/Migrations/2018_11_17_165758_add_is_verified_column_in_customers_table.php diff --git a/packages/Webkul/Customer/src/Database/migrations/2018_11_26_110500_change_gender_column_in_customers_table.php b/packages/Webkul/Customer/src/Database/Migrations/2018_11_26_110500_change_gender_column_in_customers_table.php similarity index 100% rename from packages/Webkul/Customer/src/Database/migrations/2018_11_26_110500_change_gender_column_in_customers_table.php rename to packages/Webkul/Customer/src/Database/Migrations/2018_11_26_110500_change_gender_column_in_customers_table.php diff --git a/packages/Webkul/Customer/src/Database/migrations/2019_03_28_103658_add_notes_column_in_customers_table.php b/packages/Webkul/Customer/src/Database/Migrations/2019_03_28_103658_add_notes_column_in_customers_table.php similarity index 100% rename from packages/Webkul/Customer/src/Database/migrations/2019_03_28_103658_add_notes_column_in_customers_table.php rename to packages/Webkul/Customer/src/Database/Migrations/2019_03_28_103658_add_notes_column_in_customers_table.php diff --git a/packages/Webkul/Customer/src/Database/migrations/2019_06_04_114009_add_phone_column_in_customers_table.php b/packages/Webkul/Customer/src/Database/Migrations/2019_06_04_114009_add_phone_column_in_customers_table.php similarity index 100% rename from packages/Webkul/Customer/src/Database/migrations/2019_06_04_114009_add_phone_column_in_customers_table.php rename to packages/Webkul/Customer/src/Database/Migrations/2019_06_04_114009_add_phone_column_in_customers_table.php diff --git a/packages/Webkul/Customer/src/Database/Seeders/CustomerGroupTableSeeder.php b/packages/Webkul/Customer/src/Database/Seeders/CustomerGroupTableSeeder.php index 6a83e7b4d..bbb66e3e8 100755 --- a/packages/Webkul/Customer/src/Database/Seeders/CustomerGroupTableSeeder.php +++ b/packages/Webkul/Customer/src/Database/Seeders/CustomerGroupTableSeeder.php @@ -12,6 +12,10 @@ class CustomerGroupTableSeeder extends Seeder DB::table('customer_groups')->delete(); DB::table('customer_groups')->insert([ + 'id' => 0, + 'name' => 'Guest', + 'is_user_defined' => 0, + ], [ 'id' => 1, 'name' => 'General', 'is_user_defined' => 0, @@ -19,10 +23,6 @@ class CustomerGroupTableSeeder extends Seeder 'id' => 2, 'name' => 'Wholesale', 'is_user_defined' => 0, - ], [ - 'id' => 3, - 'name' => 'Not Logged In', - 'is_user_defined' => 0, ]); } } \ No newline at end of file diff --git a/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php b/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php index 8ef088d13..7311c808c 100755 --- a/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php +++ b/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php @@ -14,6 +14,6 @@ class CustomerServiceProvider extends ServiceProvider $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'customer'); - $this->loadMigrationsFrom(__DIR__ . '/../Database/migrations'); + $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); } } From 545cd7386e939088731e0320ed6ff1d95a8c7c52 Mon Sep 17 00:00:00 2001 From: Jitendra Singh <39991107+jitendra-webkul@users.noreply.github.com> Date: Sat, 15 Jun 2019 16:49:02 +0530 Subject: [PATCH 18/33] Revert "Revert "Fixed issue with order summary rendering on cart page"" --- .../promotions/cart-rule/create.blade.php | 4 +- .../Http/Controllers/CartRuleController.php | 69 ++++++++++++++----- .../views/checkout/total/summary.blade.php | 2 +- 3 files changed, 53 insertions(+), 22 deletions(-) diff --git a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php index 64c897335..0f2d6d222 100644 --- a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php @@ -74,7 +74,7 @@
- {{--
+
@{{ errors.first('customer_groups') }} -
--}} +
diff --git a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php index 807875db1..93f1271bf 100644 --- a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php +++ b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php @@ -83,12 +83,10 @@ class CartRuleController extends Controller */ public function store() { - $data = request()->all(); - $validated = $this->validate($data, [ 'name' => 'required|string', 'description' => 'string', - // 'customer_groups' => 'required|array', + 'customer_groups' => 'required|array', 'channels' => 'required|array', 'status' => 'required|boolean', 'use_coupon' => 'boolean|required', @@ -105,32 +103,45 @@ class CartRuleController extends Controller 'label' => 'array|nullable' ]); - $data = [ - 'usage_limit' => 0, - 'per_customer' => 0 - ]; + $data = request()->all(); + // unset token + unset($data['_token']); + + // set usage limit + $data['usage_limit'] = 0; + + // set per customer usage limit + $data['per_customer'] = 0; + + // check starts from and ends till if ($data['starts_from'] == "" || $data['ends_till'] == "") { $data['starts_from'] = null; $data['ends_till'] = null; } - unset($data['_token']); + // customer groups + $customer_groups = $data['customer_groups']; - $channels = $data['channels']; + // unset customer groups + unset($data['customer_groups']); - unset($data['channels']); - - // $customer_groups = $data['customer_groups']; - // unset($data['customer_groups']); + // unset criteria unset($data['criteria']); + // channels + $channels = $data['channels']; + + // unset channels + unset($data['channels']); + + // make labels $labels = $data['label']; + // unset labels unset($data['label']); - unset($data['cart_attributes']); - unset($data['attributes']); + // prepare json object from actions if (isset($data['disc_amount']) && $data['action_type'] == config('pricerules.cart.validations.2')) { $data['actions'] = [ 'action_type' => $data['action_type'], @@ -147,22 +158,37 @@ class CartRuleController extends Controller ]; } + // prepare json object from conditions $data['actions'] = json_encode($data['actions']); + // check if all if (! isset($data['all_conditions']) || $data['all_conditions'] == "[]") { $data['conditions'] = null; } else { $data['conditions'] = json_encode($data['all_conditions']); } + // unset cart_attributes from conditions + unset($data['cart_attributes']); + + // unset attributes from conditions + unset($data['attributes']); + + // unset all_conditions from conditions unset($data['all_conditions']); + // prepare coupons if coupons are used if ($data['use_coupon']) { // if (isset($data['auto_generation']) && $data['auto_generation']) { + // auto generation is off for now $data['auto_generation'] = 0; + // save the coupon used in coupon section $coupons['code'] = $data['code']; + // set coupon usage per customer same as per_customer limit which is disabled for now + $coupons['usage_per_customer'] = $data['per_customer']; //0 is for unlimited usage + // unset coupon code from coupon section unset($data['code']); // } else { // $data['auto_generation'] = 1; @@ -181,15 +207,21 @@ class CartRuleController extends Controller // $coupons['limit'] = 0; } + // per coupon usage limit // if(isset($data['usage_limit'])) { // $coupons['limit'] = $data['usage_limit']; // } + // create a cart rule $ruleCreated = $this->cartRule->create($data); - // $ruleGroupCreated = $this->cartRule->CustomerGroupSync($customer_groups, $ruleCreated); + // create customer groups for cart rule + $ruleGroupCreated = $this->cartRule->CustomerGroupSync($customer_groups, $ruleCreated); + + // create customer groups for channels $ruleChannelCreated = $this->cartRule->ChannelSync($channels, $ruleCreated); + // prepare labels if (isset($labels['global'])) { foreach (core()->getAllChannels() as $channel) { $label1['channel_id'] = $channel->id; @@ -209,14 +241,13 @@ class CartRuleController extends Controller $ruleLabelCreated = $this->cartRuleLabel->create($label2); } + // create coupon if present if (isset($coupons)) { $coupons['cart_rule_id'] = $ruleCreated->id; - $coupons['usage_per_customer'] = $data['per_customer']; //0 is for unlimited usage - $couponCreated = $this->cartRuleCoupon->create($coupons); } - if ($ruleCreated && $ruleChannelCreated) { + if ($ruleCreated && $ruleChannelCreated && $ruleGroupCreated) { if (isset($couponCreated) && $couponCreated) { session()->flash('success', trans('admin::app.promotion.status.success-coupon')); } diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php index 151dad9aa..ca2ebabfd 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php @@ -44,7 +44,7 @@
-
+
is('checkout/cart')) v-if="hide_discount" @endif> @if (! request()->is('checkout/cart'))
From 1f5d8a8f28e218d9973fd7bbe3fc52cd81dffd68 Mon Sep 17 00:00:00 2001 From: Jitendra Singh <39991107+jitendra-webkul@users.noreply.github.com> Date: Sat, 15 Jun 2019 16:50:37 +0530 Subject: [PATCH 19/33] Revert "Revert "Development"" --- packages/Webkul/Checkout/src/Cart.php | 3 +- ...19_05_13_024326_create_cart_rule_table.php | 4 +-- .../Webkul/Discount/src/Helpers/Discount.php | 33 ++++++++++++++----- .../src/Http/Controllers/CartController.php | 8 +++-- .../views/checkout/onepage.blade.php | 8 ++++- 5 files changed, 41 insertions(+), 15 deletions(-) diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index 6bdbbffad..fc42a4823 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -1297,7 +1297,8 @@ class Cart { 'id' => $item->id, 'total' => $item->total, 'base_total' => $leastValue, - 'quantity' => $item->quantity + 'quantity' => $item->quantity, + 'price' => $item->price ]; } } diff --git a/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024326_create_cart_rule_table.php b/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024326_create_cart_rule_table.php index 03f6273ec..41859725a 100644 --- a/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024326_create_cart_rule_table.php +++ b/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024326_create_cart_rule_table.php @@ -39,8 +39,8 @@ class CreateCartRuleTable extends Migration $table->integer('sort_order')->unsigned()->default(0); $table->string('action_type')->nullable(); $table->decimal('disc_amount', 12, 4)->default(0); - $table->decimal('disc_quantity', 12, 4)->default(0); - $table->string('disc_threshold')->default(0); + $table->decimal('disc_quantity', 12, 4)->default(1); + $table->string('disc_threshold')->default(1); $table->integer('coupon_type')->default(1); $table->boolean('auto_generation')->default(0); $table->boolean('apply_to_shipping')->default(0); diff --git a/packages/Webkul/Discount/src/Helpers/Discount.php b/packages/Webkul/Discount/src/Helpers/Discount.php index cee384b68..f48e14796 100644 --- a/packages/Webkul/Discount/src/Helpers/Discount.php +++ b/packages/Webkul/Discount/src/Helpers/Discount.php @@ -310,6 +310,8 @@ class Discount \Cart::collectTotals(); + $report['grand_total'] = core()->currency(\Cart::getCart()->grand_total); + break; } } @@ -376,24 +378,36 @@ class Discount $leastWorthItem = \Cart::leastWorthItem(); $realQty = $leastWorthItem['quantity']; - if ($cart->items_qty >= $disc_threshold && $realQty >= $disc_quantity) { + if ($cart->items_qty >= $disc_threshold) { if ($action_type == config('pricerules.cart.validation.0')) { - $amountDiscounted = $leastWorthItem['total'] * ($disc_amount / 100); + $amountDiscounted = $leastWorthItem['price'] * ($disc_amount / 100); - if ($amountDiscounted > $leastWorthItem['total']) { - $amountDiscounted = $leastWorthItem['total']; + if ($realQty > $disc_quantity) { + $amountDiscounted = $amountDiscounted * $disc_quantity; + } + + if ($amountDiscounted > $leastWorthItem['price']) { + $amountDiscounted = $leastWorthItem['price']; } } else if ($action_type == config('pricerules.cart.validation.1')) { $amountDiscounted = $disc_amount; - if ($amountDiscounted > $leastWorthItem['total']) { - $amountDiscounted = $leastWorthItem['total']; + if ($realQty > $disc_quantity) { + $amountDiscounted = $amountDiscounted * $disc_quantity; + } + + if ($amountDiscounted > $leastWorthItem['price']) { + $amountDiscounted = $leastWorthItem['price']; } } else if ($action_type == config('pricerules.cart.validation.2')) { $amountDiscounted = $disc_amount; - if ($amountDiscounted > $leastWorthItem['total']) { - $amountDiscounted = $leastWorthItem['total']; + if ($realQty > $disc_quantity) { + $amountDiscounted = $amountDiscounted * $disc_quantity; + } + + if ($amountDiscounted > $leastWorthItem['price']) { + $amountDiscounted = $leastWorthItem['price']; } } } @@ -459,7 +473,6 @@ class Discount if ($existingRule->count()) { if ($existingRule->first()->delete()) { - foreach ($cart->items as $item) { if ($item->discount_amount > 0) { $item->update([ @@ -477,6 +490,8 @@ class Discount 'base_discount_amount' => 0 ]); + \Cart::collectTotals(); + return true; } else { return false; diff --git a/packages/Webkul/Shop/src/Http/Controllers/CartController.php b/packages/Webkul/Shop/src/Http/Controllers/CartController.php index 274e1939c..48ffb82bf 100755 --- a/packages/Webkul/Shop/src/Http/Controllers/CartController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/CartController.php @@ -305,12 +305,16 @@ class CartController extends Controller if ($result) { return response()->json([ 'success' => true, - 'message' => trans('admin::app.promotion.status.coupon-removed') + 'message' => trans('admin::app.promotion.status.coupon-removed'), + 'data' => [ + 'grand_total' => core()->currency(Cart::getCart()->grand_total) + ] ]); } else { return response()->json([ 'success' => false, - 'message' => trans('admin::app.promotion.status.coupon-remove-failed') + 'message' => trans('admin::app.promotion.status.coupon-remove-failed'), + 'data' => null ]); } } diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php index 071dbf16b..607d84292 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -538,7 +538,7 @@ document.getElementById("discount-detail").style.display = "block"; document.getElementById("discount-detail-discount-amount").innerHTML = response.data.result.formatted_discount; - document.getElementById("discount-detail-discount-amount").innerHTML = response.data.result.formatted_discount; + document.getElementById("grand-total-amount-detail").innerHTML = response.data.result.grand_total; }).catch(function(error) { console.log(error.data); }); @@ -550,8 +550,14 @@ axios.post('{{ route('shop.checkout.remove.coupon') }}') .then(function(response) { this_this.coupon_used = false; + this_this.code = ''; + + console.log(response.data.data.grand_total); + document.getElementById("discount-detail").style.display = "none"; + + document.getElementById("grand-total-amount-detail").innerHTML = response.data.data.grand_total; }).catch(function(error) { console.log(error.data); From 9ae4f8a80112d6015c3cf556cc9141a7f96bfbc3 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Sat, 15 Jun 2019 18:47:53 +0530 Subject: [PATCH 20/33] Fixed issues with cart rule customer groups --- .../views/promotions/cart-rule/edit.blade.php | 6 +- .../Http/Controllers/CartRuleController.php | 77 +++++++++++++++---- .../views/checkout/onepage.blade.php | 25 ------ .../views/checkout/total/summary.blade.php | 1 - 4 files changed, 63 insertions(+), 46 deletions(-) diff --git a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php index 95f4b4de1..ce21944ca 100644 --- a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php @@ -76,7 +76,7 @@
- {{--
+
- @{{ errors.first('customer_groups') }} -
--}} + @{{ errors.first('customer_groups[]') }} +
diff --git a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php index 93f1271bf..6853cd9d2 100644 --- a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php +++ b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php @@ -83,7 +83,7 @@ class CartRuleController extends Controller */ public function store() { - $validated = $this->validate($data, [ + $validated = $this->validate(request(), [ 'name' => 'required|string', 'description' => 'string', 'customer_groups' => 'required|array', @@ -114,9 +114,13 @@ class CartRuleController extends Controller // set per customer usage limit $data['per_customer'] = 0; - // check starts from and ends till - if ($data['starts_from'] == "" || $data['ends_till'] == "") { + // check if starts_from is null + if ($data['starts_from'] == "") { $data['starts_from'] = null; + } + + // check if end_till is null + if ($data['ends_till'] == "") { $data['ends_till'] = null; } @@ -282,12 +286,10 @@ class CartRuleController extends Controller */ public function update($id) { - $types = config('price_rules.cart.validations'); - $this->validate(request(), [ 'name' => 'required|string', 'description' => 'string', - // 'customer_groups' => 'required|array', + 'customer_groups' => 'required|array', 'channels' => 'required|array', 'status' => 'required|boolean', 'use_coupon' => 'boolean|required', @@ -304,35 +306,58 @@ class CartRuleController extends Controller 'label' => 'array|nullable' ]); - $data['usage_limit'] = 0; - $data['per_customer'] = 0; - + // collecting request in $data $data = request()->all(); - if ($data['starts_from'] == "" || $data['ends_till'] == "") { + // unset request token from $data + unset($data['_token']); + + // condition validation rules from config + $types = config('price_rules.cart.validations'); + + // set rule uasge limit + $data['usage_limit'] = 0; + + // set rule usage per customer + $data['per_customer'] = 0; + + // check if starts_from is null + if ($data['starts_from'] == "") { $data['starts_from'] = null; + } + + // check if end_till is null + if ($data['ends_till'] == "") { $data['ends_till'] = null; } - unset($data['_token']); - + // set channels $channels = $data['channels']; + // unset the channels from $data unset($data['channels']); - // $customer_groups = $data['customer_groups']; - // unset($data['customer_groups']); - // unset($data['criteria']); + // set customer_groups + $customer_groups = $data['customer_groups']; + // unset customer groups + unset($data['customer_groups']); + + // unset criteria from conditions + unset($data['criteria']); + + // set labels and unset them from $data if (isset($data['label'])) { $labels = $data['label']; unset($data['label']); } + // unset cart_attributes and attributes from $data unset($data['cart_attributes']); unset($data['attributes']); + // prepare actions from data for json action if (isset($data['disc_amount']) && $data['action_type'] == config('pricerules.cart.validations.2')) { $data['actions'] = [ 'action_type' => $data['action_type'], @@ -349,16 +374,20 @@ class CartRuleController extends Controller ]; } + // encode php array to json for actions $data['actions'] = json_encode($data['actions']); + // prepare conditions from data for json conditions if (! isset($data['all_conditions']) || $data['all_conditions'] == "[]") { $data['conditions'] = null; } else { $data['conditions'] = json_encode($data['all_conditions']); } + // unset all_conditions from conditions unset($data['all_conditions']); + // set coupons from $data if ($data['use_coupon']) { // if (isset($data['auto_generation']) && $data['auto_generation']) { $data['auto_generation'] = 0; @@ -386,13 +415,19 @@ class CartRuleController extends Controller // $coupons['limit'] = $data['usage_limit']; // } + // update cart rule $ruleUpdated = $this->cartRule->update($data, $id); - // $ruleGroupUpdated = $this->cartRule->CustomerGroupSync($customer_groups, $ruleUpdated); + // update customer groups for cart rule + $ruleGroupUpdated = $this->cartRule->CustomerGroupSync($customer_groups, $ruleUpdated); + + // update customer groups for cart rule $ruleChannelUpdated = $this->cartRule->ChannelSync($channels, $ruleUpdated); + // update labels $labelsUpdated = $this->cartRule->LabelSync($labels, $ruleUpdated); + // check coupons set conditions if (isset($coupons)) { $coupons['cart_rule_id'] = $ruleUpdated->id; // $coupons['usage_per_customer'] = $data['per_customer']; //0 is for unlimited usage @@ -400,7 +435,7 @@ class CartRuleController extends Controller $couponUpdated = $ruleUpdated->coupons->update($coupons); } - if ($ruleUpdated && $ruleChannelUpdated) { + if ($ruleUpdated && $ruleGroupUpdated && $ruleChannelUpdated) { if (isset($couponUpdated) && $couponUpdated) { session()->flash('info', trans('admin::app.promotion.status.success-coupon')); } @@ -415,6 +450,9 @@ class CartRuleController extends Controller return redirect()->route($this->_config['redirect']); } + /** + * Delete + */ public function destroy($id) { $cartRule = $this->cartRule->findOrFail($id); @@ -430,6 +468,11 @@ class CartRuleController extends Controller } } + /** + * Get Countries and states list from core helpers + * + * @return Array + */ public function getStatesAndCountries() { $countries = core()->countries()->toArray(); diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php index 607d84292..02e593fbc 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -374,31 +374,6 @@ this.templateRender() : '') ]); - }, - - methods: { - onSubmit: function() { - var this_this = this; - - axios.post('{{ route('shop.checkout.check.coupons') }}', { - code: this_this.code - }).then(function(response) { - console.log(response.data); - }).catch(function(error) { - console.log(error.data); - }); - }, - - removeCoupon: function () { - var this_this = this; - - axios.post('{{ route('shop.checkout.remove.coupon') }}') - .then(function(response) { - console.log(response.data); - }).catch(function(error) { - console.log(error.data); - }); - } } }) diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php index ca2ebabfd..f5229a87b 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php @@ -24,7 +24,6 @@
@endif -
discount_amount && $cart->discount_amount > 0) style="display: block;" @else style="display: none;" @endif>
\ No newline at end of file diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php index ca2ebabfd..4db1a1d51 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php @@ -44,28 +44,35 @@
-
is('checkout/cart')) v-if="hide_discount" @endif> +
is('checkout/cart')) v-if="parseInt(discount)" @endif> @if (! request()->is('checkout/cart')) -
-
-
-
- -
+ @if (! $cart->coupon_code) +
+
+ +
+ +
- @{{ error_message }} + @{{ error_message }} - - + + +
-
+ @else +
+
+ -
-
- - + +
-
+ @endif @endif
\ No newline at end of file From b93bc11c659038e4a08ac4fa130002bf79e31a74 Mon Sep 17 00:00:00 2001 From: jitendra Date: Sat, 15 Jun 2019 22:28:21 +0530 Subject: [PATCH 24/33] Fixed js error in checkout page --- .../Shop/src/Resources/views/checkout/onepage.blade.php | 4 +++- .../Shop/src/Resources/views/checkout/total/summary.blade.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php index 0a5f67920..4c025487a 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -480,6 +480,8 @@ return { templateRender: null, + coupon_code: null, + error_message: '' } }, @@ -506,7 +508,7 @@ onSubmit: function() { var this_this = this; - axios.post('{{ route('shop.checkout.check.coupons') }}', {code: this_this.code}) + axios.post('{{ route('shop.checkout.check.coupons') }}', {code: this_this.coupon_code}) .then(function(response) { this_this.$emit('onApplyCoupon') }) diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php index 4db1a1d51..01de2b767 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php @@ -51,7 +51,7 @@
- +
@{{ error_message }} From 15abe379e0425bd80454e1dc1f84267800b04dd3 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Sun, 16 Jun 2019 17:26:06 +0530 Subject: [PATCH 25/33] Changed frontend attributes and syntax fixes in checkout --- .../promotions/cart-rule/create.blade.php | 3 +- .../views/promotions/cart-rule/edit.blade.php | 28 +++- .../Webkul/Discount/src/Helpers/Discount.php | 3 + .../Http/Controllers/CartRuleController.php | 6 +- .../Http/Controllers/OnepageController.php | 20 +-- .../views/checkout/onepage.blade.php | 144 +++++++++--------- .../views/checkout/onepage/review.blade.php | 3 +- .../views/checkout/total/summary.blade.php | 13 +- .../assets/js/components/accordian.vue | 2 +- 9 files changed, 128 insertions(+), 94 deletions(-) diff --git a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php index 0f2d6d222..e9721e456 100644 --- a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php @@ -476,7 +476,6 @@ this.conditions_list.push(this.cart_object); this.cart_object = { - criteria: null, attribute: null, condition: null, value: [] @@ -526,7 +525,7 @@ onSubmit: function (e) { if (this.conditions_list.length != 0) { - this.conditions_list.test_mode = this.match_criteria; + this.conditions_list.push({'criteria': this.match_criteria}); } this.all_conditions = JSON.stringify(this.conditions_list); diff --git a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php index ce21944ca..66d974f05 100644 --- a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php @@ -567,12 +567,32 @@ }, onSubmit: function (e) { + if (this.conditions_list.length != 0) { - // if (this.conditions_list.length != 0) { - // this.conditions_list.push(this.match_criteria); - // } + indexes = []; - console.log(JSON.stringify(this.conditions_list)); + for (i in this.conditions_list) { + if (this.conditions_list[i].hasOwnProperty('criteria') && ! this.conditions_list[i].hasOwnProperty('attribute')) { + indexes.push(i); + } + } + + if (indexes.length > 1) { + for (i in indexes) { + console.log(indexes[i]); + if (this.conditions_list.length ) + this.conditions_list.splice(indexes[i], 1); + } + } else { + + } + + return false; + + this.conditions_list.push({'criteria': this.match_criteria}); + } + + return false; this.all_conditions = JSON.stringify(this.conditions_list); diff --git a/packages/Webkul/Discount/src/Helpers/Discount.php b/packages/Webkul/Discount/src/Helpers/Discount.php index f48e14796..3d7b7ab39 100644 --- a/packages/Webkul/Discount/src/Helpers/Discount.php +++ b/packages/Webkul/Discount/src/Helpers/Discount.php @@ -502,6 +502,8 @@ class Discount } protected function testIfAllConditionAreTrue($conditions, $cart) { + array_pop($conditions); + $shipping_address = $cart->getShippingAddressAttribute() ?? ''; $shipping_method = $cart->shipping_method ?? ''; @@ -524,6 +526,7 @@ class Discount $test_conditions = config('pricerules.cart.conditions'); $result = 1; + foreach ($conditions as $condition) { $actual_value = ${$condition->attribute}; $test_value = $condition->value; diff --git a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php index 6853cd9d2..d23bf0715 100644 --- a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php +++ b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php @@ -79,7 +79,7 @@ class CartRuleController extends Controller } /** - * @return Redirect + * @return redirect */ public function store() { @@ -451,7 +451,9 @@ class CartRuleController extends Controller } /** - * Delete + * Deletes the cart rule + * + * @return JSON */ public function destroy($id) { diff --git a/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php b/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php index eaf2454d6..587bd800b 100755 --- a/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php @@ -99,13 +99,13 @@ class OnepageController extends Controller $data['billing']['address1'] = implode(PHP_EOL, array_filter($data['billing']['address1'])); $data['shipping']['address1'] = implode(PHP_EOL, array_filter($data['shipping']['address1'])); - if (Cart::hasError() || !Cart::saveCustomerAddress($data) || ! $rates = Shipping::collectRates()) - return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403); - Cart::applyNonCoupon(); Cart::collectTotals(); + if (Cart::hasError() || !Cart::saveCustomerAddress($data) || ! $rates = Shipping::collectRates()) + return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403); + return response()->json($rates); } @@ -118,13 +118,13 @@ class OnepageController extends Controller { $shippingMethod = request()->get('shipping_method'); - if (Cart::hasError() || !$shippingMethod || !Cart::saveShippingMethod($shippingMethod)) - return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403); - Cart::applyNonCoupon(); Cart::collectTotals(); + if (Cart::hasError() || !$shippingMethod || !Cart::saveShippingMethod($shippingMethod)) + return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403); + return response()->json(Payment::getSupportedPaymentMethods()); } @@ -137,15 +137,15 @@ class OnepageController extends Controller { $payment = request()->get('payment'); + Cart::applyNonCoupon(); + + Cart::collectTotals(); + if (Cart::hasError() || !$payment || !Cart::savePaymentMethod($payment)) return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403); $cart = Cart::getCart(); - Cart::applyNonCoupon(); - - Cart::collectTotals(); - return response()->json([ 'jump_to_section' => 'review', 'html' => view('shop::checkout.onepage.review', compact('cart', 'rule'))->render() diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php index 02e593fbc..93613d39c 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -71,8 +71,12 @@
-
- +
+ +
+ +
+
- +
@@ -341,42 +345,6 @@ } }) - var summaryTemplateRenderFns = []; - - Vue.component('summary-section', { - inject: ['$validator'], - - data: function() { - return { - templateRender: null, - - code: null, - - coupon_used: false, - - hide_discount: 0 - } - }, - - staticRenderFns: summaryTemplateRenderFns, - - mounted: function() { - this.templateRender = summaryHtml.render; - - for (var i in summaryHtml.staticRenderFns) { - summaryTemplateRenderFns.push(summaryHtml.staticRenderFns[i]); - } - }, - - render: function(h) { - return h('div', [ - (this.templateRender ? - this.templateRender() : - '') - ]); - } - }) - var shippingTemplateRenderFns = []; Vue.component('shipping-section', { @@ -460,40 +428,78 @@ eventBus.$emit('after-payment-method-selected'); } } - }) + }); var reviewTemplateRenderFns = []; Vue.component('review-section', { - data: function() { + props: ['active'], + + data: function () { return { templateRender: null, - code: '', - - hide_discount: 1, - - coupon_used: false, - - error_message: '' + hide_discount: null, } }, staticRenderFns: reviewTemplateRenderFns, - mounted: function() { + mounted: function () { + this.hide_discount = this.active; + this.templateRender = reviewHtml.render; + for (var i in reviewHtml.staticRenderFns) { reviewTemplateRenderFns.push(reviewHtml.staticRenderFns[i]); } - - @if ($cart->coupon_code != null) - this.code = '{{ $cart->coupon_code }}'; - this.coupon_used = true; - @endif }, render: function(h) { + return h('div', [ + (this.templateRender ? + this.templateRender() : + '') + ] + ); + } + }); + + var summaryTemplateRenderFns = []; + + Vue.component('summary-section', { + inject: ['$validator'], + props: ['active'], + + data: function () { + return { + templateRender: null, + + code: null, + + coupon_used: false, + + hide_discount: null, + + error_message: '', + + call_count: 0, + } + }, + + staticRenderFns: summaryTemplateRenderFns, + + mounted: function () { + this.hide_discount = this.active; + + this.templateRender = summaryHtml.render; + + for (var i in summaryHtml.staticRenderFns) { + summaryTemplateRenderFns.push(summaryHtml.staticRenderFns[i]); + } + }, + + render: function (h) { return h('div', [ (this.templateRender ? this.templateRender() : @@ -510,12 +516,8 @@ }).then(function(response) { this_this.coupon_used = true; - document.getElementById("discount-detail").style.display = "block"; - document.getElementById("discount-detail-discount-amount").innerHTML = response.data.result.formatted_discount; - - document.getElementById("grand-total-amount-detail").innerHTML = response.data.result.grand_total; + this_this.getOrderSummary(); }).catch(function(error) { - console.log(error.data); }); }, @@ -527,20 +529,24 @@ this_this.coupon_used = false; this_this.code = ''; + }).catch(function(error) {}); + }, - console.log(response.data.data.grand_total); + getOrderSummary () { + var this_this = this; - document.getElementById("discount-detail").style.display = "none"; + this.$http.get("{{ route('shop.checkout.summary') }}") + .then(function(response) { + this_this.resetSummary = false; - document.getElementById("grand-total-amount-detail").innerHTML = response.data.data.grand_total; - }).catch(function(error) { - console.log(error.data); - - this_this.error_message = '{{ __('shop::app.checkout.onepage.total.cannot-apply-coupon') }}' - }); - } + summaryHtml = Vue.compile(response.data.html) + setTimeout(function() { + this_this.resetSummary = true; + }, 0); + }).catch(function (error) {}) + }, } - }); + }) @endpush \ No newline at end of file diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage/review.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage/review.blade.php index 5341e42e4..d200f8a9c 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage/review.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage/review.blade.php @@ -155,7 +155,8 @@
- @include('shop::checkout.total.summary', ['cart' => $cart]) + {{-- @include('shop::checkout.total.summary', ['cart' => $cart]) --}} +
\ No newline at end of file diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php index f5229a87b..678798244 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php @@ -1,4 +1,4 @@ -
+

{{ __('shop::app.checkout.total.order-summary') }}

@@ -35,7 +35,6 @@
-