From bec9ebe7fbf3d7970dcf550122811ff5ee0794d1 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Fri, 14 Jun 2019 19:52:58 +0530 Subject: [PATCH] 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 -
+ +