feat(cart): implement restoration and reservation of source cart on expired checkout modification

This commit is contained in:
2026-08-21 10:10:28 -03:00
parent 0510c1aa12
commit 3a2dc8b7e0
4 changed files with 90 additions and 3 deletions

View File

@@ -25,6 +25,8 @@ class SourceCartService
return false;
}
$this->restoreReservations($sourceCart);
/** @var Cart|null $activeCart */
$activeCart = Cart::query()
->where('tenant_codigo', $purchase->tenant_codigo)
@@ -62,6 +64,25 @@ class SourceCartService
return true;
}
private function restoreReservations(Cart $cart): void
{
$items = $cart->items()->orderBy('id')->lockForUpdate()->get();
$items->load([
'catalogItem.inventory',
'catalogItem.bundleComponents.catalogItem.inventory',
'catalogItem.bundleComponents.variant.inventory',
'variant.inventory',
'variant.catalogItem',
]);
foreach ($items as $item) {
$selection = $item->selectedItem();
if ($selection !== null) {
$this->reservations->restore($item, $selection);
}
}
}
public function syncItemQuantity(
Purchase $purchase,
PurchaseItem $purchaseItem,