feat(checkout): track current cart purchase
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Domains\Purchase\Services;
|
||||
|
||||
use App\Domains\Cart\Models\Cart;
|
||||
use App\Domains\Purchase\Exceptions\PurchaseExpiredException;
|
||||
use App\Domains\Purchase\Models\Purchase;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class PurchaseStateGuard
|
||||
{
|
||||
@@ -21,4 +23,18 @@ class PurchaseStateGuard
|
||||
throw new PurchaseExpiredException;
|
||||
}
|
||||
}
|
||||
|
||||
public function lockCurrentCart(Purchase $purchase): Cart
|
||||
{
|
||||
/** @var Cart|null $cart */
|
||||
$cart = $purchase->cart()->withTrashed()->lockForUpdate()->first();
|
||||
|
||||
if ($cart === null || $cart->current_purchase_id !== $purchase->getKey()) {
|
||||
throw ValidationException::withMessages([
|
||||
'purchase' => __('api.purchase.not_current'),
|
||||
]);
|
||||
}
|
||||
|
||||
return $cart;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user