From 76d60c328b054b0986cf5ad5d14123d3dcd64c3b Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Sun, 28 Dec 2025 12:19:56 +0100 Subject: [PATCH] I cart/items --- src/Models/Cart.php | 27 +++++++++++++++++++++++++++ src/Models/CartItem.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/Models/Cart.php b/src/Models/Cart.php index b0c938b..978bdab 100644 --- a/src/Models/Cart.php +++ b/src/Models/Cart.php @@ -1126,6 +1126,33 @@ class Cart extends Model $pricePerDay = $priceModel?->getCurrentPrice($cartable->isOnSale()); $regularPricePerDay = $priceModel?->getCurrentPrice(false) ?? $pricePerDay; $poolPriceId = $priceModel?->id; + + // Still try to find a single item for allocation even with pool's direct price + // This ensures allocated_single_item_name is always set for pool items + if (!$poolSingleItem) { + $singleItems = $cartable->singleProducts; + foreach ($singleItems as $single) { + // Find first single with available capacity + $available = $single->manage_stock ? $single->getAvailableStock() : PHP_INT_MAX; + if ($available > 0) { + // Check how many are already in cart for this single + $inCart = $this->items() + ->where('purchasable_id', $cartable->getKey()) + ->where('purchasable_type', get_class($cartable)) + ->get() + ->filter(function ($item) use ($single) { + $meta = $item->getMeta(); + return isset($meta->allocated_single_item_id) && $meta->allocated_single_item_id == $single->id; + }) + ->sum('quantity'); + + if ($available === PHP_INT_MAX || $inCart < $available) { + $poolSingleItem = $single; + break; + } + } + } + } } } else { $pricePerDay = $cartable->getCurrentPrice(); diff --git a/src/Models/CartItem.php b/src/Models/CartItem.php index 46da253..eca38f7 100644 --- a/src/Models/CartItem.php +++ b/src/Models/CartItem.php @@ -110,6 +110,34 @@ class CartItem extends Model return $this->quantity * $this->price; } + /** + * Get display subtotal - returns null for booking items not ready for checkout + * Use this for display purposes when you want null for incomplete bookings + * + * @return int|null + */ + public function getDisplaySubtotalAttribute(): ?int + { + if (!$this->is_ready_to_checkout && $this->is_booking) { + return null; + } + return $this->attributes['subtotal'] ?? null; + } + + /** + * Get display price - returns null for booking items not ready for checkout + * Use this for display purposes when you want null for incomplete bookings + * + * @return int|null + */ + public function getDisplayPriceAttribute(): ?int + { + if (!$this->is_ready_to_checkout && $this->is_booking) { + return null; + } + return $this->attributes['price'] ?? null; + } + public function scopeForCart($query, $cartId) { return $query->where('cart_id', $cartId);