WIP: cart
This commit is contained in:
@@ -77,8 +77,10 @@ const productId = computed(() => route.params.id);
|
||||
const product = ref({});
|
||||
const cart = useCartStore();
|
||||
|
||||
const rowId = computed(() => cart.generateRowId(productId.value, product.value.options));
|
||||
|
||||
const buttonText = computed(() => {
|
||||
const item = cart.items.find(i => i.productId === productId.value);
|
||||
const item = cart.getItem(rowId.value);
|
||||
return item && item.quantity > 0
|
||||
? `В корзине`
|
||||
: 'Добавить в корзину'
|
||||
@@ -95,21 +97,19 @@ const canAddToCart = computed(() => {
|
||||
&& !item.value;
|
||||
});
|
||||
|
||||
console.log(required);
|
||||
|
||||
return required.length === 0;
|
||||
});
|
||||
|
||||
const isInCartNow = computed(() => {
|
||||
return cart.hasProduct(productId.value);
|
||||
return cart.hasItem(rowId.value);
|
||||
});
|
||||
|
||||
const quantity = computed(() => {
|
||||
return cart.getQuantity(productId.value);
|
||||
return cart.getQuantity(rowId.value);
|
||||
});
|
||||
|
||||
function actionBtnClick() {
|
||||
if (cart.hasProduct(productId.value)) {
|
||||
if (cart.hasItem(rowId.value)) {
|
||||
window.Telegram.WebApp.HapticFeedback.selectionChanged();
|
||||
router.push({name: 'cart.show'});
|
||||
} else {
|
||||
@@ -120,10 +120,10 @@ function actionBtnClick() {
|
||||
|
||||
function setQuantity(newQuantity) {
|
||||
if (newQuantity === 0) {
|
||||
cart.removeProduct(productId.value);
|
||||
cart.removeItem(rowId.value);
|
||||
window.Telegram.WebApp.HapticFeedback.notificationOccurred('warning');
|
||||
} else {
|
||||
cart.setQuantity(productId.value, newQuantity);
|
||||
cart.setQuantity(rowId.value, newQuantity);
|
||||
window.Telegram.WebApp.HapticFeedback.selectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user