diff --git a/src/app/features/store/pages/checkout-page/checkout-page.component.ts b/src/app/features/store/pages/checkout-page/checkout-page.component.ts index 6e67b73..1acce85 100644 --- a/src/app/features/store/pages/checkout-page/checkout-page.component.ts +++ b/src/app/features/store/pages/checkout-page/checkout-page.component.ts @@ -199,9 +199,28 @@ export class CheckoutPageComponent implements OnInit, OnDestroy { } if (editing && !this.canModifyCart()) { - await this.router.navigate(['/'], { - queryParams: { openCart: true }, - }); + const tenant = this.tenantService.tenant(); + const purchaseId = this.createdPurchaseId(); + + if (!tenant || !purchaseId) { + return; + } + + this.isPreparingItemEdit.set(true); + try { + await this.checkoutService.cancelPurchase(tenant.codigo, purchaseId); + this.createdPurchaseId.set(null); + this.createdPurchase.set(null); + await firstValueFrom(this.cartService.loadCart()); + await this.router.navigate(['/'], { + queryParams: { openCart: true }, + }); + } catch (error) { + console.error('Failed to restore cart for editing:', error); + } finally { + this.isPreparingItemEdit.set(false); + } + return; }