diff --git a/components/PvzMap.vue b/components/PvzMap.vue index b80d5a0..c404c2c 100644 --- a/components/PvzMap.vue +++ b/components/PvzMap.vue @@ -41,7 +41,7 @@ const initMap = async (lat: number, lon: number) => { }) mapInstance.value = map - props.pickupPoints.forEach((point) => { + props?.pickupPoints?.forEach((point) => { const placemark = new window.ymaps.Placemark( [point?.position?.latitude, point?.position?.longitude], { diff --git a/composables/useCart.ts b/composables/useCart.ts index de9e3dc..5ed3cc5 100644 --- a/composables/useCart.ts +++ b/composables/useCart.ts @@ -1,4 +1,5 @@ import { useStorage } from '@vueuse/core' +import { useProduct } from './useProduct' export interface ICartItem { variation_id: number @@ -22,9 +23,22 @@ export const useCart = () => { cartItem?.variation_id === item?.variation_id), 1) } + const cartProducts = computed(() => cart?.value?.line_items?.map((line_item) => { + const { productsData } = useProduct(line_item?.variation_id.toString()) + return productsData + })) + + const cartSum = computed(() => cartProducts?.value?.reduce((acc, curr) => { + acc += Number(curr?.value?.price) + return acc + }, 0)) + return { cart, cartAddItem, cartRemoveItem, + + cartProducts, + cartSum, } } diff --git a/composables/useCheckout.ts b/composables/useCheckout.ts index a987f78..0920601 100644 --- a/composables/useCheckout.ts +++ b/composables/useCheckout.ts @@ -25,10 +25,10 @@ export const useCheckout = createSharedComposable(() => { }, ] - const currentCheckoutStep = ref(checkoutSteps.find(value => value.title === route.path.split('/').pop())) + const currentCheckoutStep = ref(checkoutSteps.find(value => value.title === route.path.split('/').pop()) || checkoutSteps[0]) function previewStep() { - const findIndex = checkoutSteps.findIndex(value => value.step === currentCheckoutStep?.value.step) + const findIndex = checkoutSteps.findIndex(value => value.step === currentCheckoutStep.value.step) if (findIndex !== 0) { currentCheckoutStep.value = checkoutSteps[findIndex - 1] router.push(`/checkout/${currentCheckoutStep?.value.title}`) @@ -39,13 +39,18 @@ export const useCheckout = createSharedComposable(() => { } function nextStep() { - const findIndex = checkoutSteps.findIndex(value => value.step === currentCheckoutStep?.value.step) + const findIndex = checkoutSteps.findIndex(value => value.step === currentCheckoutStep.value.step) if (findIndex + 1 !== checkoutSteps.length) { currentCheckoutStep.value = checkoutSteps[findIndex + 1] router.push(`/checkout/${currentCheckoutStep?.value.title}`) } } + function setStep(pathName: string) { + currentCheckoutStep.value = checkoutSteps.find(value => value.title === pathName) || checkoutSteps[0] + router.push(`/checkout/${pathName}`) + } + return { contacts, setContacts, @@ -55,5 +60,6 @@ export const useCheckout = createSharedComposable(() => { previewStep, nextStep, + setStep, } }) diff --git a/package.json b/package.json index 1dc19ea..86aee6c 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@nuxt/fonts": "0.11.4", "@nuxt/icon": "1.15.0", "@nuxt/image": "1.10.0", - "@nuxt/ui": "3.2.0", + "@nuxt/ui": "^4.0.1", "@nuxtjs/i18n": "^10.0.4", "@tanstack/vue-query": "^5.75.5", "@tanstack/vue-query-devtools": "^5.87.1", @@ -26,7 +26,7 @@ "dayjs": "^1.11.13", "decimal.js": "^10.5.0", "maska": "^3.2.0", - "nuxt": "^3.17.6", + "nuxt": "^4.1.3", "swiper": "^12.0.2", "typescript": "^5.6.3", "vue": "^3.5.17", diff --git a/pages/cart.vue b/pages/cart.vue index 1fdd55d..4d81260 100644 --- a/pages/cart.vue +++ b/pages/cart.vue @@ -9,25 +9,17 @@ -
-
-
{{ `Товары: ${cart?.line_items?.length}` }}
-
{{ `Сумма: ${cart?.line_items?.length}` }}
- - - Перейти к оформлению - -
-
+ diff --git a/pages/checkout/contacts.vue b/pages/checkout/contacts.vue index 4e3788c..359ee0f 100644 --- a/pages/checkout/contacts.vue +++ b/pages/checkout/contacts.vue @@ -140,14 +140,14 @@