@php
$sortedProducts = [];
$otherProducts = [];
// First, categorize products based on 'location'
foreach($products as $product) {
if (!empty($product->location) && $product->location > 0) {
$sortedProducts[$product->location] = $product;
} else {
$otherProducts[] = $product;
}
}
// Sort products based on 'location'
ksort($sortedProducts);
// Take the first 9 sorted products
$finalProducts = array_slice($sortedProducts, 0, 9);
$remainingSlots = 9 - count($finalProducts);
// If there are slots remaining, fill them with products that don't have a 'location'
if ($remainingSlots > 0) {
$finalProducts = array_merge($finalProducts, array_slice($otherProducts, 0, $remainingSlots));
}
// Store any remaining products (both sorted and unsorted) for additional display
$moreProducts = array_merge(array_slice($sortedProducts, 9), array_slice($otherProducts, $remainingSlots));
@endphp
{{-- Loop through final products and display them --}}
@foreach($products as $key => $product)
@endif --}}
@php
$isOutOfStock = true;
/*if (!is_null($quantity)) {
foreach ($quantity as $key => $value) {
if ($value > 0) {
$isOutOfStock = false;
break; // No need to check further if one of the quantities is available
}
}
} */
if($quantity){
$isOutOfStock = false;
}
@endphp
@if($isOutOfStock)