coupon section fix in review-order component

This commit is contained in:
Prashant Singh 2019-06-14 19:52:58 +05:30
parent 1e865986c4
commit bec9ebe7fb
4 changed files with 37 additions and 26 deletions

View File

@ -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' => [

View File

@ -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;

View File

@ -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);
});

View File

@ -37,9 +37,9 @@
</div>
<div v-if="hide_discount">
@if (! request()->is('checkout/cart') && ! $cart->coupon_code)
@if (! request()->is('checkout/cart'))
<div class="discount">
<div class="discount-group">
<div class="discount-group" v-if="! coupon_used">
<form class="coupon-form" method="post" @submit.prevent="onSubmit">
<div class="control-group mt-20" :class="[errors.has('code') ? 'has-error' : '']">
<input type="text" class="control" value="" v-model="code" name="code" placeholder="Enter Coupon Code" v-validate="'required'" style="width: 100%">
@ -49,8 +49,8 @@
</form>
</div>
</div>
@else
<div class="discount-details-group">
<div class="discount-details-group" v-if="coupon_used">
<div class="item-detail">
<label>{{ __('shop::app.checkout.total.coupon-applied') }}</label>
<label class="right" style="display: inline-flex; align-items: center;">{{ $cart->coupon_code }} <span class="icon cross-icon" title="{{ __('shop::app.checkout.total.remove-coupon') }}" v-on:click="removeCoupon"></span></label>