feat: Add event association to purchases; implement event relationship in models, update migration, and enhance tests

This commit is contained in:
2026-08-04 11:45:03 -03:00
parent 1de08c1ca4
commit 8aa3a26ee7
7 changed files with 83 additions and 0 deletions

View File

@@ -26,6 +26,11 @@ class CheckoutService
public function startCheckout(Tenant $tenant, int $userId, array $purchaseData): Purchase
{
return DB::transaction(function () use ($tenant, $userId, $purchaseData): Purchase {
/** @var Tenant $tenant */
$tenant = Tenant::query()
->lockForUpdate()
->findOrFail($tenant->getKey());
$directItem = $purchaseData['direct_item'] ?? null;
$cartId = isset($purchaseData['cart_id']) ? (int) $purchaseData['cart_id'] : null;
unset($purchaseData['direct_item'], $purchaseData['cart_id']);
@@ -615,6 +620,7 @@ class CheckoutService
...$purchaseData,
'cart_id' => $cartId,
'tenant_codigo' => $tenant->codigo,
'event_id' => $tenant->active_event_id,
'user_id' => $userId,
'status' => Purchase::STATUS_CREATED,
'payment_method' => null,