diff --git a/src/app/core/services/checkout.service.ts b/src/app/core/services/checkout.service.ts index 9d7d996..3d54c7d 100644 --- a/src/app/core/services/checkout.service.ts +++ b/src/app/core/services/checkout.service.ts @@ -11,16 +11,21 @@ export interface UpdatePurchaseCustomerPayload { email: string; } +export interface DirectCheckoutItem { + catalog_item_id: number; + variant_id: number | null; + cantidad: number; +} + export type StartCheckoutPayload = | { cart_id: number; } | { - direct_item: { - catalog_item_id: number; - variant_id: number | null; - cantidad: number; - }; + direct_item: DirectCheckoutItem; + } + | { + direct_items: DirectCheckoutItem[]; }; export interface PurchaseStatusResponse { diff --git a/src/app/features/store/pages/store-home-page/store-home-page.component.ts b/src/app/features/store/pages/store-home-page/store-home-page.component.ts index da6c79f..d9eea52 100644 --- a/src/app/features/store/pages/store-home-page/store-home-page.component.ts +++ b/src/app/features/store/pages/store-home-page/store-home-page.component.ts @@ -10,7 +10,7 @@ import { } from '@angular/core'; import { HttpErrorResponse } from '@angular/common/http'; import { ActivatedRoute, Router } from '@angular/router'; -import { firstValueFrom, Subscription } from 'rxjs'; +import { Subscription } from 'rxjs'; import { CartService } from '../../../../core/services/cart/cart.service'; import { AuthService } from '../../../../core/services/auth/auth.service'; @@ -210,16 +210,13 @@ export class StoreHomePageComponent implements OnInit, OnDestroy { catalogItemId: number, variantIds: number[], ) { - for (const variantId of variantIds) { - await firstValueFrom(this.cartService.addItem(catalogItemId, variantId, 1)); - } - - const cartId = this.cartService.cart()?.id; - if (cartId === null || cartId === undefined) { - throw new Error('No se pudo crear el carrito para las entradas seleccionadas.'); - } - - return checkoutService.startCheckout(tenantCode, { cart_id: cartId }); + return checkoutService.startCheckout(tenantCode, { + direct_items: variantIds.map((variantId) => ({ + catalog_item_id: catalogItemId, + variant_id: variantId, + cantidad: 1, + })), + }); } protected onAddToCart(event: ProductListCartEvent): void {