I cart/items

This commit is contained in:
Fabian @ Blax Software 2025-12-28 12:19:56 +01:00
parent 2f3c0dc61f
commit 76d60c328b
2 changed files with 55 additions and 0 deletions

View File

@ -1126,6 +1126,33 @@ class Cart extends Model
$pricePerDay = $priceModel?->getCurrentPrice($cartable->isOnSale()); $pricePerDay = $priceModel?->getCurrentPrice($cartable->isOnSale());
$regularPricePerDay = $priceModel?->getCurrentPrice(false) ?? $pricePerDay; $regularPricePerDay = $priceModel?->getCurrentPrice(false) ?? $pricePerDay;
$poolPriceId = $priceModel?->id; $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 { } else {
$pricePerDay = $cartable->getCurrentPrice(); $pricePerDay = $cartable->getCurrentPrice();

View File

@ -110,6 +110,34 @@ class CartItem extends Model
return $this->quantity * $this->price; 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) public function scopeForCart($query, $cartId)
{ {
return $query->where('cart_id', $cartId); return $query->where('cart_id', $cartId);