This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user