feat(checkout): update checkout process to handle multiple direct items
This commit is contained in:
@@ -21,9 +21,6 @@ export type StartCheckoutPayload =
|
||||
| {
|
||||
cart_id: number;
|
||||
}
|
||||
| {
|
||||
direct_item: DirectCheckoutItem;
|
||||
}
|
||||
| {
|
||||
direct_items: DirectCheckoutItem[];
|
||||
};
|
||||
|
||||
@@ -184,21 +184,23 @@ export class StoreHomePageComponent implements OnInit, OnDestroy {
|
||||
try {
|
||||
const checkoutService = this.injector.get(CheckoutService);
|
||||
const variantIds = event.variantIds ?? [];
|
||||
const purchase =
|
||||
variantIds.length > 1
|
||||
? await this.startTicketCheckout(
|
||||
checkoutService,
|
||||
tenant.codigo,
|
||||
event.product.id,
|
||||
variantIds,
|
||||
)
|
||||
: await checkoutService.startCheckout(tenant.codigo, {
|
||||
direct_item: {
|
||||
const directItems =
|
||||
variantIds.length > 0
|
||||
? variantIds.map((variantId) => ({
|
||||
catalog_item_id: event.product.id,
|
||||
variant_id: variantId,
|
||||
cantidad: 1,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
catalog_item_id: event.product.id,
|
||||
variant_id: event.variant ?? null,
|
||||
cantidad: event.quantity,
|
||||
},
|
||||
});
|
||||
];
|
||||
const purchase = await checkoutService.startCheckout(tenant.codigo, {
|
||||
direct_items: directItems,
|
||||
});
|
||||
await this.router.navigate(['/checkout'], { queryParams: { purchase: purchase.id } });
|
||||
} catch (error) {
|
||||
console.error('Failed to create direct purchase:', error);
|
||||
@@ -219,21 +221,6 @@ export class StoreHomePageComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
private async startTicketCheckout(
|
||||
checkoutService: CheckoutService,
|
||||
tenantCode: string,
|
||||
catalogItemId: number,
|
||||
variantIds: number[],
|
||||
) {
|
||||
return checkoutService.startCheckout(tenantCode, {
|
||||
direct_items: variantIds.map((variantId) => ({
|
||||
catalog_item_id: catalogItemId,
|
||||
variant_id: variantId,
|
||||
cantidad: 1,
|
||||
})),
|
||||
});
|
||||
}
|
||||
|
||||
protected onAddToCart(event: ProductListCartEvent): void {
|
||||
this.cartService.addItem(event.product.id, event.variant ?? null, event.quantity).subscribe({
|
||||
next: (response) => {
|
||||
|
||||
Reference in New Issue
Block a user