feat(checkout): update checkout process to handle multiple direct items

This commit is contained in:
2026-08-12 14:46:15 -03:00
parent 159ec36cb2
commit 85c31579e2
2 changed files with 13 additions and 29 deletions

View File

@@ -21,9 +21,6 @@ export type StartCheckoutPayload =
| { | {
cart_id: number; cart_id: number;
} }
| {
direct_item: DirectCheckoutItem;
}
| { | {
direct_items: DirectCheckoutItem[]; direct_items: DirectCheckoutItem[];
}; };

View File

@@ -184,21 +184,23 @@ export class StoreHomePageComponent implements OnInit, OnDestroy {
try { try {
const checkoutService = this.injector.get(CheckoutService); const checkoutService = this.injector.get(CheckoutService);
const variantIds = event.variantIds ?? []; const variantIds = event.variantIds ?? [];
const purchase = const directItems =
variantIds.length > 1 variantIds.length > 0
? await this.startTicketCheckout( ? variantIds.map((variantId) => ({
checkoutService, catalog_item_id: event.product.id,
tenant.codigo, variant_id: variantId,
event.product.id, cantidad: 1,
variantIds, }))
) : [
: await checkoutService.startCheckout(tenant.codigo, { {
direct_item: {
catalog_item_id: event.product.id, catalog_item_id: event.product.id,
variant_id: event.variant ?? null, variant_id: event.variant ?? null,
cantidad: event.quantity, cantidad: event.quantity,
}, },
}); ];
const purchase = await checkoutService.startCheckout(tenant.codigo, {
direct_items: directItems,
});
await this.router.navigate(['/checkout'], { queryParams: { purchase: purchase.id } }); await this.router.navigate(['/checkout'], { queryParams: { purchase: purchase.id } });
} catch (error) { } catch (error) {
console.error('Failed to create direct purchase:', 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 { protected onAddToCart(event: ProductListCartEvent): void {
this.cartService.addItem(event.product.id, event.variant ?? null, event.quantity).subscribe({ this.cartService.addItem(event.product.id, event.variant ?? null, event.quantity).subscribe({
next: (response) => { next: (response) => {