feat(checkout): use reserved cart for ticket purchases
This commit is contained in:
@@ -113,7 +113,9 @@ export class CategoryItemsPageComponent {
|
||||
|
||||
if (!this.injector.get(AuthService).user()) {
|
||||
await this.router.navigate(['/login'], {
|
||||
queryParams: { returnUrl: `/producto/${event.product.id}` },
|
||||
queryParams: {
|
||||
returnUrl: event.reservedInCart ? this.router.url : `/producto/${event.product.id}`,
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -126,15 +128,25 @@ export class CategoryItemsPageComponent {
|
||||
|
||||
this.creatingDirectPurchase.set(true);
|
||||
try {
|
||||
const purchase = await this.injector.get(CheckoutService).startCheckout(tenant.codigo, {
|
||||
direct_items: [
|
||||
{
|
||||
catalog_item_id: event.product.id,
|
||||
variant_id: event.variant ?? null,
|
||||
cantidad: event.quantity,
|
||||
},
|
||||
],
|
||||
});
|
||||
const reservedCartId = event.reservedInCart ? (this.cartService.cart()?.id ?? null) : null;
|
||||
if (event.reservedInCart && reservedCartId === null) {
|
||||
this.toastService.danger('No se pudo identificar el carrito reservado.');
|
||||
return;
|
||||
}
|
||||
const purchase = await this.injector.get(CheckoutService).startCheckout(
|
||||
tenant.codigo,
|
||||
reservedCartId !== null
|
||||
? { cart_id: reservedCartId }
|
||||
: {
|
||||
direct_items: [
|
||||
{
|
||||
catalog_item_id: event.product.id,
|
||||
variant_id: event.variant ?? null,
|
||||
cantidad: event.quantity,
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
await this.router.navigate(['/checkout'], { queryParams: { purchase: purchase.id } });
|
||||
} catch (error) {
|
||||
console.error('Failed to create direct purchase:', error);
|
||||
|
||||
@@ -145,7 +145,9 @@ export class SearchPageComponent {
|
||||
|
||||
if (!this.injector.get(AuthService).user()) {
|
||||
await this.router.navigate(['/login'], {
|
||||
queryParams: { returnUrl: `/producto/${event.product.id}` },
|
||||
queryParams: {
|
||||
returnUrl: event.reservedInCart ? this.router.url : `/producto/${event.product.id}`,
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -158,15 +160,25 @@ export class SearchPageComponent {
|
||||
|
||||
this.creatingDirectPurchase.set(true);
|
||||
try {
|
||||
const purchase = await this.injector.get(CheckoutService).startCheckout(tenant.codigo, {
|
||||
direct_items: [
|
||||
{
|
||||
catalog_item_id: event.product.id,
|
||||
variant_id: event.variant ?? null,
|
||||
cantidad: event.quantity,
|
||||
},
|
||||
],
|
||||
});
|
||||
const reservedCartId = event.reservedInCart ? (this.cartService.cart()?.id ?? null) : null;
|
||||
if (event.reservedInCart && reservedCartId === null) {
|
||||
this.toastService.danger('No se pudo identificar el carrito reservado.');
|
||||
return;
|
||||
}
|
||||
const purchase = await this.injector.get(CheckoutService).startCheckout(
|
||||
tenant.codigo,
|
||||
reservedCartId !== null
|
||||
? { cart_id: reservedCartId }
|
||||
: {
|
||||
direct_items: [
|
||||
{
|
||||
catalog_item_id: event.product.id,
|
||||
variant_id: event.variant ?? null,
|
||||
cantidad: event.quantity,
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
await this.router.navigate(['/checkout'], { queryParams: { purchase: purchase.id } });
|
||||
} catch (error) {
|
||||
console.error('Failed to create direct purchase:', error);
|
||||
|
||||
@@ -169,7 +169,9 @@ export class StoreHomePageComponent implements OnInit, OnDestroy {
|
||||
|
||||
if (!this.injector.get(AuthService).user()) {
|
||||
await this.router.navigate(['/login'], {
|
||||
queryParams: { returnUrl: `/producto/${event.product.id}` },
|
||||
queryParams: {
|
||||
returnUrl: event.reservedInCart ? this.router.url : `/producto/${event.product.id}`,
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -183,6 +185,11 @@ export class StoreHomePageComponent implements OnInit, OnDestroy {
|
||||
this.creatingDirectPurchase.set(true);
|
||||
try {
|
||||
const checkoutService = this.injector.get(CheckoutService);
|
||||
const reservedCartId = event.reservedInCart ? (this.cartService.cart()?.id ?? null) : null;
|
||||
if (event.reservedInCart && reservedCartId === null) {
|
||||
this.toastService.danger('No se pudo identificar el carrito reservado.');
|
||||
return;
|
||||
}
|
||||
const variantIds = event.variantIds ?? [];
|
||||
const directItems =
|
||||
variantIds.length > 0
|
||||
@@ -198,9 +205,10 @@ export class StoreHomePageComponent implements OnInit, OnDestroy {
|
||||
cantidad: event.quantity,
|
||||
},
|
||||
];
|
||||
const purchase = await checkoutService.startCheckout(tenant.codigo, {
|
||||
direct_items: directItems,
|
||||
});
|
||||
const purchase = await checkoutService.startCheckout(
|
||||
tenant.codigo,
|
||||
reservedCartId !== null ? { cart_id: reservedCartId } : { direct_items: directItems },
|
||||
);
|
||||
await this.router.navigate(['/checkout'], { queryParams: { purchase: purchase.id } });
|
||||
} catch (error) {
|
||||
console.error('Failed to create direct purchase:', error);
|
||||
|
||||
Reference in New Issue
Block a user