feat(cart): implement restoration and reservation of source cart on expired checkout modification
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user