@php use Botble\Ecommerce\Models\Brand; use Botble\Ecommerce\Models\ProductAttributeSet; use Botble\Base\Enums\BaseStatusEnum; // Get brands $brands = []; try { $brands = Brand::where('status', 'published')->orderBy('order', 'asc')->get(); } catch (\Exception $e) {} // Get tyre size attributes $widthSet = null; $profileSet = null; $diameterSet = null; try { // Get the attribute sets for width, profile, diameter (order 0,1,2) $attributeSets = ProductAttributeSet::with(['attributes' => function($query) { $query->orderBy('order', 'asc'); }]) ->where('status', BaseStatusEnum::PUBLISHED) ->where('is_searchable', 1) ->orderBy('order', 'asc') ->get(); // Find our three size-related attribute sets // Prefer using attribute set 'order' (1 => width, 2 => profile, 3 => diameter) foreach ($attributeSets as $set) { if ($set->order === 1) { $widthSet = $set; continue; } if ($set->order === 2) { $profileSet = $set; continue; } if ($set->order === 3) { $diameterSet = $set; continue; } } // Fallback by title matching if not found by order if (! $widthSet || ! $profileSet || ! $diameterSet) { foreach ($attributeSets as $set) { $title = strtolower($set->title); if (! $widthSet && in_array($title, ['width', 'tyre width'])) { $widthSet = $set; } if (! $profileSet && in_array($title, ['profile', 'tyre profile', 'size'])) { $profileSet = $set; } if (! $diameterSet && in_array($title, ['diameter', 'tyre diameter', 'rim size'])) { $diameterSet = $set; } } } } catch (\Exception $e) {} @endphp