@php $choicesMatrix = $product->choices_matrix ?? []; if(is_object($choicesMatrix)) $choicesMatrix = (array)$choicesMatrix; @endphp @once @include('themes.includes.components.product-choices.styles') @include('themes.includes.components.product-choices.scripts') @endonce @if(isset($choicesMatrix['choices']) && count($choicesMatrix['choices']) > 0)
@foreach($choicesMatrix['choices'] as $choice) @php $choice = (array)$choice; @endphp
{{ $choice['choices_name'] }}
@foreach($choice['childs'] as $option) @php $option = (array)$option; $firstWord = explode(' ', $option['choices_name'])[0]; $hasImage = isset($option['choices_image']) && $option['choices_image']; $imgSrc = $hasImage ? ($imagesBaseUrl ?? '') .'uploads/'.env('accountId').'/choices/original/'.$option['choices_image'] : ''; // Safe retrieval of show_name with explicit casting $showName = 1; // Default to 1 (Show Name) if (isset($choice['choices_show_name']) && $choice['choices_show_name'] !== null && $choice['choices_show_name'] !== '') { $showName = (int)$choice['choices_show_name']; } // Determine Display Mode // 1. Full (Name + Image): ShowName=1 && HasImage // 2. Circle Only (Image): ShowName=0 && HasImage // 3. Text Only: !HasImage (Fallback to text even if ShowName=0) $isFull = ($showName === 1 && $hasImage); $isCircleOnly = ($showName === 0 && $hasImage); $isTextOnly = (!$hasImage); $containerClass = 'choice-item d-flex align-items-center justify-content-center position-relative cursor-pointer'; if ($isFull) $containerClass .= ' has-icon'; if ($isTextOnly) $containerClass .= ' text-only'; if ($isCircleOnly) $containerClass .= ' circle-only'; @endphp
{{-- Icon / Circle Wrapper --}} @if(!$isTextOnly)
@if($hasImage) {{ $option['choices_name'] }} {{-- Fallback if image fails to load --}} @else {{-- Fallback for Circle Only Mode when no image exists in DB --}}
{{ $firstWord }}
@endif
@endif {{-- Text Label (Show if Full OR Text Only) --}} @if(!$isCircleOnly) {{ $option['choices_name'] }} @endif
@endforeach
@endforeach
@endif