feat(checkout): restore cart before modifying items

This commit is contained in:
2026-08-20 16:28:58 -03:00
parent cfa1091116
commit d636b2b82b

View File

@@ -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;
}