refactor(stock): make expired reservations terminal
This commit is contained in:
@@ -72,6 +72,18 @@ class ReleaseCheckoutService
|
||||
|
||||
$cart = $purchase->cart()->withTrashed()->lockForUpdate()->first();
|
||||
|
||||
if ($targetStatus === Purchase::STATUS_CANCELLED
|
||||
&& $cart?->status === 'active'
|
||||
&& in_array($purchase->status, [
|
||||
Purchase::STATUS_CREATED,
|
||||
Purchase::STATUS_PENDING_PAYMENT,
|
||||
], true)) {
|
||||
$this->reservations->returnToCart($purchase, $cart);
|
||||
$purchase->update(['status' => Purchase::STATUS_CANCELLED]);
|
||||
|
||||
return $this->loadPurchase($purchase);
|
||||
}
|
||||
|
||||
if (
|
||||
$targetStatus === Purchase::STATUS_EXPIRED
|
||||
&& (! in_array($purchase->status, [
|
||||
@@ -118,17 +130,17 @@ class ReleaseCheckoutService
|
||||
}
|
||||
|
||||
if ($cart->status === 'active') {
|
||||
$cartUpdate = [
|
||||
'current_purchase_id' => null,
|
||||
];
|
||||
if ($targetStatus !== Purchase::STATUS_EXPIRED) {
|
||||
$cartUpdate['current_stock_reservation_id'] = null;
|
||||
}
|
||||
|
||||
Cart::query()
|
||||
->whereKey($cart->getKey())
|
||||
->where('current_purchase_id', $purchase->getKey())
|
||||
->update([
|
||||
'current_purchase_id' => null,
|
||||
'current_stock_reservation_id' => null,
|
||||
]);
|
||||
|
||||
if ($targetStatus === Purchase::STATUS_CANCELLED) {
|
||||
$this->reservations->syncCart($cart);
|
||||
}
|
||||
->update($cartUpdate);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user