refactor(checkout): simplify direct item handling in checkout process

This commit is contained in:
2026-08-12 14:09:11 -03:00
parent 0e5f6dceb0
commit 30b8527c9a
2 changed files with 18 additions and 16 deletions

View File

@@ -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 {

View File

@@ -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 {