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