feat: add shipping address selection to checkout
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+7
-2
@@ -119,7 +119,7 @@ export const useOrderStore = defineStore('order', () => {
|
||||
* روش تسویه را انتخاب میکند.
|
||||
* اقلام همه شرکتها در یک فاکتور واحد ثبت میشوند.
|
||||
*/
|
||||
async function submitOrder(cart: Cart): Promise<Order> {
|
||||
async function submitOrder(cart: Cart, shippingAddress?: string): Promise<Order> {
|
||||
if (!cart.items.length) {
|
||||
throw new Error('سبد خرید خالی است.')
|
||||
}
|
||||
@@ -134,12 +134,17 @@ export const useOrderStore = defineStore('order', () => {
|
||||
throw new Error('شرکت سبد مشخص نیست. سبد را خالی کنید و دوباره اضافه کنید.')
|
||||
}
|
||||
|
||||
const addressLine = shippingAddress?.trim()
|
||||
? `آدرس ارسال: ${shippingAddress.trim()}`
|
||||
: ''
|
||||
const notes = [addressLine, cart.notes?.trim()].filter(Boolean).join('\n')
|
||||
|
||||
try {
|
||||
const order = await apiRequest<Order>('/orders', {
|
||||
method: 'POST',
|
||||
body: {
|
||||
companyId: companyIds[0],
|
||||
notes: cart.notes,
|
||||
notes: notes || undefined,
|
||||
items: cart.items.map((item) => ({
|
||||
productId: item.productId,
|
||||
meterage: Number(item.meterage),
|
||||
|
||||
Reference in New Issue
Block a user