alsaze 2e01f58e67
Some checks failed
Deploy / build (push) Has been cancelled
refactoring
2025-11-21 12:48:00 +03:00

87 lines
2.3 KiB
Vue

<template>
<div class="cart">
<div v-if="cart.line_items.length > 0" class="cart__items">
<div
v-for="cartItem in cart?.line_items"
:key="cartItem.variation_id"
>
<CartItem :cart-item="cartItem" />
</div>
</div>
<div v-else>
Корзина пока что пуста
</div>
<ClientOnly>
<PayBlock :is-summary="true" />
</ClientOnly>
</div>
</template>
<script setup lang="ts">
import type { WooOrderCreateResponse } from '#shared/woo_orders_create'
import { useCart } from '~/composables'
import PayBlock from '../components/PayBlock.vue'
const route = useRoute()
const { cart, cartRemoveAllItems } = useCart()
const { checkoutContacts, checkoutPickupPoint } = useCheckout()
const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
// Зарпос должен быть в админке bsbp, ждём доступов. Текущее решение просто создает order в WooCommerce
onMounted(async () => {
if (!route?.query?.ID || cart.value.line_items.length === 0)
return
await wait(5000)
await useFetch<WooOrderCreateResponse>('/api/woo_orders_create', {
method: 'POST',
body: {
payment_method: 'bacs',
payment_method_title: 'Оплата по реквизитам',
set_paid: true,
billing: {
first_name: checkoutContacts?.value?.name,
last_name: checkoutContacts?.value?.surname,
phone: checkoutContacts?.value?.phone,
email: checkoutContacts?.value?.email,
address_1: checkoutPickupPoint.value?.address?.full_address,
postcode: checkoutPickupPoint.value?.address?.postal_code,
city: checkoutPickupPoint?.value?.address?.locality,
country: 'RU',
},
transaction_id: route?.query?.ID,
line_items: cart.value.line_items,
status: 'processing',
},
})
cartRemoveAllItems()
})
</script>
<style lang="scss">
.cart {
margin-top: 120px;
margin-inline: auto;
max-width: 1200px;
display: flex;
flex-direction: row;
justify-content: space-between;
@include mobile {
margin-top: 20px;
flex-direction: column;
padding-inline: 16px;
}
&__items {
display: flex;
flex-direction: column;
gap: 16px;
}
}
</style>