feat(telecart): add vouchers and coupons (#9)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {defineStore} from "pinia";
|
||||
import {isNotEmpty} from "@/helpers.js";
|
||||
import {addToCart, cartEditItem, cartRemoveItem, getCart} from "@/utils/ftch.js";
|
||||
import {addToCart, cartEditItem, cartRemoveItem, getCart, setCoupon, setVoucher} from "@/utils/ftch.js";
|
||||
|
||||
export const useCartStore = defineStore('cart', {
|
||||
state: () => ({
|
||||
@@ -12,6 +12,8 @@ export const useCartStore = defineStore('cart', {
|
||||
error_warning: '',
|
||||
attention: '',
|
||||
success: '',
|
||||
coupon: '',
|
||||
voucher: '',
|
||||
}),
|
||||
|
||||
getters: {
|
||||
@@ -104,5 +106,43 @@ export const useCartStore = defineStore('cart', {
|
||||
this.isLoading = false;
|
||||
}
|
||||
},
|
||||
|
||||
async applyCoupon() {
|
||||
try {
|
||||
this.isLoading = true;
|
||||
this.error_warning = '';
|
||||
const response = await setCoupon(this.coupon);
|
||||
|
||||
if (response.error) {
|
||||
this.error_warning = response.error;
|
||||
} else {
|
||||
await this.getProducts();
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
this.error_warning = 'Возникла ошибка';
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
},
|
||||
|
||||
async applyVoucher() {
|
||||
try {
|
||||
this.isLoading = true;
|
||||
this.error_warning = '';
|
||||
const response = await setVoucher(this.voucher);
|
||||
|
||||
if (response.error) {
|
||||
this.error_warning = response.error;
|
||||
} else {
|
||||
await this.getProducts();
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
this.error_warning = 'Возникла ошибка';
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user