Merge pull request #5382 from devansh-webkul/coupon-issue

This commit is contained in:
Devansh 2021-12-03 13:52:03 +05:30 committed by GitHub
commit 5eef58e474
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 51 additions and 35 deletions

View File

@ -46,66 +46,82 @@
}
},
watch: {
coupon_code: function (value) {
if (value != '') {
this.error_message = '';
}
}
},
methods: {
applyCoupon: function() {
if (! this.coupon_code.length)
if (! this.coupon_code.length) {
this.error_message = '{{ __('shop::app.checkout.total.invalid-coupon') }}';
return;
}
this.error_message = null;
this.disable_button = true;
let code = this.coupon_code;
axios.post(
'{{ route('shop.checkout.cart.coupon.apply') }}', {code}
).then(response => {
if (response.data.success) {
this.$emit('onApplyCoupon');
this.applied_coupon = this.coupon_code;
this.coupon_code = '';
window.flashMessages = [{'type': 'alert-success', 'message': response.data.message}];
axios
.post(
'{{ route('shop.checkout.cart.coupon.apply') }}', {code}
).then(response => {
if (response.data.success) {
this.$emit('onApplyCoupon');
this.$root.addFlashMessages();
this.applied_coupon = this.coupon_code;
this.coupon_code = '';
this.redirectIfCartPage();
} else {
this.error_message = response.data.message;
}
window.flashMessages = [{'type': 'alert-success', 'message': response.data.message}];
this.disable_button = false;
}).catch(error => {
this.error_message = error.response.data.message;
this.$root.addFlashMessages();
this.disable_button = false;
});
this.redirectIfCartPage();
} else {
this.error_message = response.data.message;
}
this.disable_button = false;
}).catch(error => {
this.error_message = error.response.data.message;
this.disable_button = false;
});
},
removeCoupon: function () {
var self = this;
let self = this;
axios.delete('{{ route('shop.checkout.coupon.remove.coupon') }}')
.then(function(response) {
self.$emit('onRemoveCoupon')
axios
.delete('{{ route('shop.checkout.coupon.remove.coupon') }}')
.then(function(response) {
self.$emit('onRemoveCoupon')
self.applied_coupon = '';
self.disable_button = false;
self.applied_coupon = '';
window.flashMessages = [{'type': 'alert-success', 'message': response.data.message}];
self.disable_button = false;
self.$root.addFlashMessages();
window.flashMessages = [{'type': 'alert-success', 'message': response.data.message}];
self.redirectIfCartPage();
})
.catch(function(error) {
window.flashMessages = [{'type': 'alert-error', 'message': error.response.data.message}];
self.$root.addFlashMessages();
self.$root.addFlashMessages();
});
self.redirectIfCartPage();
})
.catch(function(error) {
window.flashMessages = [{'type': 'alert-error', 'message': error.response.data.message}];
self.$root.addFlashMessages();
});
},
redirectIfCartPage: function() {
if (this.route_name != 'shop.checkout.cart.index')
return;
if (this.route_name != 'shop.checkout.cart.index') return;
setTimeout(function() {
window.location.reload();