refactor(stock): propagate reservation expiration

This commit is contained in:
2026-08-25 16:09:52 -03:00
parent d2a2b323e0
commit 82570fe941
3 changed files with 22 additions and 62 deletions

View File

@@ -129,13 +129,25 @@ class ReleaseCheckoutService
return;
}
if ($cart->status === 'active') {
if ($targetStatus === Purchase::STATUS_EXPIRED
&& in_array($cart->status, [Cart::STATUS_ACTIVE, Cart::STATUS_CHECKOUT], true)) {
Cart::query()
->whereKey($cart->getKey())
->where('current_purchase_id', $purchase->getKey())
->where('current_stock_reservation_id', $purchase->stock_reservation_id)
->update([
'status' => Cart::STATUS_EXPIRED,
'current_purchase_id' => null,
]);
return;
}
if ($cart->status === Cart::STATUS_ACTIVE) {
$cartUpdate = [
'current_purchase_id' => null,
'current_stock_reservation_id' => null,
];
if ($targetStatus !== Purchase::STATUS_EXPIRED) {
$cartUpdate['current_stock_reservation_id'] = null;
}
Cart::query()
->whereKey($cart->getKey())
@@ -145,7 +157,7 @@ class ReleaseCheckoutService
return;
}
if ($cart->status !== 'checkout') {
if ($cart->status !== Cart::STATUS_CHECKOUT) {
return;
}