feat(telecart): add vouchers and coupons (#9)

This commit is contained in:
2025-10-20 20:00:31 +03:00
parent 78ca4fd309
commit ac24f0376b
10 changed files with 149 additions and 14 deletions

View File

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