diff --git a/storefront/app/components/cards/product.vue b/storefront/app/components/cards/product.vue index bce677cd..5e02858b 100644 --- a/storefront/app/components/cards/product.vue +++ b/storefront/app/components/cards/product.vue @@ -173,7 +173,7 @@ const isProductInCart = computed(() => { ); } else { return (cookieCart.value ?? []).some( - (item) => item.product === props.product?.uuid + (item) => item.productUuid === props.product?.uuid ); } }); @@ -186,7 +186,7 @@ const productInCartQuantity = computed(() => { return productEdge?.node.quantity ?? 0; } else { const cartItem = (cookieCart.value ?? []).find( - (item) => item.product === props.product.uuid + (item) => item.productUuid === props.product.uuid ); return cartItem?.quantity ?? 0; } diff --git a/storefront/app/components/home/blog.vue b/storefront/app/components/home/blog.vue index a6c2433d..9ae5eb8f 100644 --- a/storefront/app/components/home/blog.vue +++ b/storefront/app/components/home/blog.vue @@ -27,7 +27,7 @@ const {t} = useI18n(); const filteredPosts = computed(() => { const excludedSlugs = Object.values(docsSlugs); - return props.posts.filter(post => !excludedSlugs.includes(post.node.slug)); + return props.posts?.filter(post => !excludedSlugs.includes(post.node.slug)); }); diff --git a/storefront/app/composables/brands/useBrands.ts b/storefront/app/composables/brands/useBrands.ts index 063b7d34..6d51a1c0 100644 --- a/storefront/app/composables/brands/useBrands.ts +++ b/storefront/app/composables/brands/useBrands.ts @@ -25,7 +25,7 @@ export function useBrands(args: IBrandArgs = {}) { brandSearch: args.brandSearch, }); - const pending = ref(false); + const pending = ref(false); const brands = ref([]); const pageInfo = ref<{ hasNextPage: boolean; diff --git a/storefront/app/composables/orders/useOrderOverwrite.ts b/storefront/app/composables/orders/useOrderOverwrite.ts index d27a2188..2a39ada2 100644 --- a/storefront/app/composables/orders/useOrderOverwrite.ts +++ b/storefront/app/composables/orders/useOrderOverwrite.ts @@ -155,7 +155,7 @@ export function useOrderOverwrite() { if (bulkResult?.data?.bulkOrderAction?.order) { cartStore.setCurrentOrders(bulkResult.data.bulkOrderAction.order); $notify({ - message: t('popup.success.bulkRemoveOrder'), + message: t('popup.success.bulkAddOrder'), type: 'success', }); } @@ -172,7 +172,7 @@ export function useOrderOverwrite() { const current = Array.isArray(cookieCart.value) ? [...cookieCart.value] : []; const index = current.findIndex( - (item) => item.product === args.productUuid + (item) => item.productUuid === args.productUuid ); if (index !== -1) { @@ -182,7 +182,7 @@ export function useOrderOverwrite() { }; } else { current.push({ - product: args.productUuid, + productUuid: args.productUuid, quantity: 1, }); } @@ -205,7 +205,7 @@ export function useOrderOverwrite() { : []; const index = current.findIndex( - (item) => item.product === args.productUuid + (item) => item.productUuid === args.productUuid ); if (index !== -1) { @@ -233,7 +233,7 @@ export function useOrderOverwrite() { case 'removeKind': { cookieCart.value = (cookieCart.value ?? []).filter( - (item) => item.product.uuid !== args.productUuid + (item) => item.productUuid !== args.productUuid ); $notify({ @@ -258,18 +258,59 @@ export function useOrderOverwrite() { } case 'bulk': { - const bulkResult = await bulkMutate({ - orderUuid: orderUuid.value, - action: args.bulkAction, - products: args.products, - }); + const current = Array.isArray(cookieCart.value) + ? [...cookieCart.value] + : []; - if (bulkResult?.data?.bulkOrderAction?.order) { - cartStore.setCurrentOrders(bulkResult.data.bulkOrderAction.order); - $notify({ - message: t('popup.success.bulkRemoveOrder'), - type: 'success', - }); + if (!args.products?.length) return; + + switch (args.bulkAction) { + case 'add': { + args.products.forEach(({ uuid }) => { + const index = current.findIndex( + item => item.productUuid === uuid + ); + + if (index !== -1) { + current[index] = { + ...current[index], + quantity: current[index].quantity + 1, + }; + } else { + current.push({ + productUuid: uuid, + quantity: 1, + }); + } + }); + + cookieCart.value = current; + + $notify({ + message: t('popup.success.bulkAddOrder'), + type: 'success', + }); + + break; + } + + case 'remove': { + const uuidsToRemove = args.products.map(p => p.uuid); + + cookieCart.value = current.filter( + item => !uuidsToRemove.includes(item.productUuid) + ); + + $notify({ + message: t('popup.success.bulkRemoveOrder'), + type: 'success', + }); + + break; + } + + default: + console.error('Invalid bulkAction'); } break; diff --git a/storefront/app/composables/orders/useOrderSync.ts b/storefront/app/composables/orders/useOrderSync.ts index 6f9c1fc2..d84e44aa 100644 --- a/storefront/app/composables/orders/useOrderSync.ts +++ b/storefront/app/composables/orders/useOrderSync.ts @@ -38,13 +38,13 @@ export function useOrderSync() { const productsToSync = []; for (const cartItem of cookieCartItems) { - const apiQuantity = apiProductMap.get(cartItem.product.uuid) || 0; + const apiQuantity = apiProductMap.get(cartItem.productUuid) || 0; const quantityDifference = cartItem.quantity - apiQuantity; if (quantityDifference > 0) { for (let i = 0; i < quantityDifference; i++) { productsToSync.push({ - uuid: cartItem.product.uuid, + uuid: cartItem.productUuid, }); } } diff --git a/storefront/app/composables/products/useExactProducts.ts b/storefront/app/composables/products/useExactProducts.ts new file mode 100644 index 00000000..96707979 --- /dev/null +++ b/storefront/app/composables/products/useExactProducts.ts @@ -0,0 +1,37 @@ +import { GET_EXACT_PRODUCTS } from '@graphql/queries/standalone/products'; +import type {IProduct, IProductExactResponse} from '@types'; + +export function useExactProducts() { + const products = ref([]); + const error = ref(null); + const pending = ref(false); + + const getExactProducts = async (identificators: string[], identificatorType: string) => { + pending.value = true; + + const { data, error: mistake } = useAsyncQuery(GET_EXACT_PRODUCTS, { + identificators: identificators, + identificatorType: identificatorType + }); + + if (data.value?.retrieveExactProducts) { + products.value = data.value?.retrieveExactProducts; + } + + if (mistake.value) { + error.value = mistake.value; + } + + pending.value = false; + } + + watch(error, (e) => { + if (e) console.error('useExactProducts error:', e); + }); + + return { + products, + pending, + getExactProducts, + }; +} diff --git a/storefront/app/composables/wishlist/useWishlistSync.ts b/storefront/app/composables/wishlist/useWishlistSync.ts index 693820a5..e1232729 100644 --- a/storefront/app/composables/wishlist/useWishlistSync.ts +++ b/storefront/app/composables/wishlist/useWishlistSync.ts @@ -40,9 +40,7 @@ export function useWishlistSync() { type: 'bulk', bulkAction: 'add', isBulkSync: true, - products: productsToAdd.map((p) => ({ - uuid: p, - })), + products: productsToAdd.map(uuid => ({ uuid })) }); if (bulkResult?.data?.bulkWishlistAction?.wishlist) { diff --git a/storefront/app/graphql/mutations/wishlist.ts b/storefront/app/graphql/mutations/wishlist.ts index 5385f5a7..74cc4412 100644 --- a/storefront/app/graphql/mutations/wishlist.ts +++ b/storefront/app/graphql/mutations/wishlist.ts @@ -53,7 +53,7 @@ export const BULK_WISHLIST = gql` mutation bulkWishlistAction( $wishlistUuid: UUID!, $action: String!, - $products: [BulkActionOrderProductInput]! + $products: [BulkProductInput]! ) { bulkWishlistAction( wishlistUuid: $wishlistUuid diff --git a/storefront/app/graphql/queries/standalone/products.ts b/storefront/app/graphql/queries/standalone/products.ts index 979efb09..1d4d46dd 100644 --- a/storefront/app/graphql/queries/standalone/products.ts +++ b/storefront/app/graphql/queries/standalone/products.ts @@ -83,3 +83,18 @@ export const GET_PRODUCT_TAGS = gql` } ${PRODUCT_FRAGMENT} `; + +export const GET_EXACT_PRODUCTS = gql` + query getExactProducts( + $identificators: [String]!, + $identificatorType: String! + ) { + retrieveExactProducts( + identificators: $identificators, + identificatorType: $identificatorType + ) { + ...Product + } + } + ${PRODUCT_FRAGMENT} +`; diff --git a/storefront/app/pages/cart.vue b/storefront/app/pages/cart.vue index 917d3782..267da952 100644 --- a/storefront/app/pages/cart.vue +++ b/storefront/app/pages/cart.vue @@ -5,7 +5,10 @@

{{ t('cart.title') }}

-

({{ t('cart.items', productsInCartQuantity, { count: productsInCartQuantity }) }})

+ +

({{ t('cart.items', productsInCartQuantity, { count: productsInCartQuantity }) }})

+
+

{{ totalPrice }}$

-
-
- + +
+
+ +
+

{{ t('cart.empty') }}

-

{{ t('cart.empty') }}

-
+
@@ -34,6 +39,7 @@