refactor(checkout): keep source cart active

This commit is contained in:
2026-08-21 13:42:30 -03:00
parent 79e721ae63
commit 1650176aa0
10 changed files with 98 additions and 216 deletions

View File

@@ -86,7 +86,9 @@ class UserPurchaseLimitService
$excludedCartId !== null,
fn ($query) => $query->whereKeyNot($excludedCartId),
))
->whereHas('stockReservations', fn ($query) => $query->where('status', 'active'))
->whereHas('stockReservations', fn ($query) => $query
->where('status', 'active')
->whereNull('purchase_id'))
->sum('cantidad');
if ($purchasedQuantity + $checkoutQuantity + $reservedCartQuantity + $requestedQuantity > $limit) {
@@ -152,7 +154,9 @@ class UserPurchaseLimitService
->whereHas('cart', fn ($query) => $query
->where('user_id', $userId)
->where('status', 'active'))
->whereHas('stockReservations', fn ($query) => $query->where('status', 'active'))
->whereHas('stockReservations', fn ($query) => $query
->where('status', 'active')
->whereNull('purchase_id'))
->groupBy('catalog_item_id')
->pluck('quantity', 'catalog_item_id');