schon/storefront/app/pages/cart.vue
Alexandr SaVBaD Waltz c36135d78d feat(storefront): add wishlist and guest cart support with cookie persistence
Enhancements:
- Introduced `wishlist.vue` for displaying and managing the wishlist.
- Added guest cart and wishlist handling via cookies for unauthenticated users.
- Implemented synchronization logic for wishlist and cart (`useOrderSync` and `useWishlistSync`) upon user login.
- Updated `cart.vue` layout with a bulk 'add all to cart' button for wishlist items.
- Enhanced `post.vue` prop handling for improved type safety.

Fixes:
- Fixed breadcrumbs console log removal in `useBreadcrumbs.ts`.
- Corrected and unified translations in `en-gb.json` for cart and wishlist descriptions.
- Fixed stale routes in footer (`terms-and-condition` -> `terms-and-conditions`, etc.).

Extras:
- Refactored composables `useWishlistOverwrite` and `useOrderOverwrite` for cookie-based fallback.
- Applied code styling improvements, organized imports, and optimized API requests in Apollo plugin.
2026-02-28 17:39:17 +03:00

143 lines
No EOL
3.3 KiB
Vue

<template>
<div class="cart">
<div class="container">
<div class="cart__wrapper">
<div class="cart__top">
<h1 class="cart__top-title">{{ t('cart.title') }}</h1>
<div class="cart__top-inner">
<p>({{ t('cart.items', productsInCartQuantity, { count: productsInCartQuantity }) }})</p>
<ui-button
:type="'button'"
class="cart__top-button"
@click="buyOrder"
>
<icon name="material-symbols:add" size="20" />
{{ t('buttons.checkout') }}
</ui-button>
</div>
</div>
<div class="cart__list">
<div class="cart__list-inner" v-if="productsInCart.length">
<cards-product
v-for="product in productsInCart"
:key="product.node.uuid"
:product="product.node.product"
/>
</div>
<p class="cart__empty" v-else>{{ t('cart.empty') }}</p>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import {usePageTitle} from "@composables/utils";
import {useOrderBuy} from "~/composables/orders";
const {t} = useI18n();
const cartStore = useCartStore();
const userStore = useUserStore();
const { $appHelpers } = useNuxtApp();
const isAuthenticated = computed(() => userStore.isAuthenticated);
const cookieCart = useCookie($appHelpers.COOKIES_CART_KEY, {
default: () => [],
path: '/',
});
const { buyOrder } = useOrderBuy();
const productsInCart = computed(() => {
if (isAuthenticated.value) {
return cartStore.currentOrder ? cartStore.currentOrder.orderProducts.edges : [];
} else {
return cookieCart.value.map(product => ({
node: {
product: item.product,
quantity: item.quantity
}
}));
}
});
const totalPrice = computed(() => {
if (isAuthenticated.value) {
return cartStore.currentOrder ? cartStore.currentOrder.totalPrice : 0;
} else {
return cookieCart.value.reduce((acc, item) => {
return acc + (item.product.price * item.quantity);
}, 0);
}
});
const productsInCartQuantity = computed(() => {
if (isAuthenticated.value) {
let count = 0;
cartStore.currentOrder?.orderProducts?.edges.forEach((el) => {
count = count + el.node.quantity;
});
return count;
} else {
return cookieCart.value.reduce((acc, item) => acc + item.quantity, 0);
}
});
const { setPageTitle } = usePageTitle();
setPageTitle(t('breadcrumbs.cart'));
</script>
<style lang="scss" scoped>
.cart {
padding-block: 50px 100px;
background-color: $white;
&__wrapper {
display: flex;
flex-direction: column;
gap: 50px;
}
&__top {
display: flex;
align-items: center;
justify-content: space-between;
&-inner {
display: flex;
align-items: center;
gap: 35px;
}
&-title {
color: #1a1a1a;
font-family: "Playfair Display", sans-serif;
font-size: 36px;
font-weight: 600;
letter-spacing: -0.5px;
}
& p {
color: #4b5563;
font-size: 18px;
font-weight: 400;
letter-spacing: -0.5px;
}
&-button {
width: fit-content;
padding-inline: 25px;
}
}
&__list {
&-inner {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 25px;
}
}
}
</style>