@php use Botble\Ecommerce\Models\ProductSpecificationAttributeTranslation; use Botble\Ecommerce\Models\SpecificationTable; $currentLangCode = ProductSpecificationAttributeTranslation::getCurrentLanguageCode(); // Prefer the table's sorted-by-group view so we can render group headings. // Falls back to the flat visible-attributes list when a product has no // table assigned (e.g. legacy data). $specificationTable = $product->specificationTable ?? null; $groupedSpecs = $specificationTable ? collect($specificationTable->getSortedAttributesForProduct($product)) ->map(function ($section) use ($product) { $section['attributes'] = $section['attributes']->filter(function ($attribute) use ($product) { $pivot = $product->specificationAttributes->firstWhere('id', $attribute->getKey()); return $pivot && ! (bool) $pivot->pivot->getAttribute('hidden'); }); return $section; }) ->filter(fn ($section) => $section['attributes']->isNotEmpty()) ->values() : collect(); $visibleAttributes = $groupedSpecs->isEmpty() ? $product->getVisibleSpecificationAttributes() : null; @endphp
@if ($groupedSpecs->isNotEmpty()) @foreach ($groupedSpecs as $section) @php $group = $section['group']; $attributes = $section['attributes']; @endphp
{{ $group->name }}
@foreach ($attributes as $attribute)
{{ $attribute->name }}
@include(Theme::getThemeNamespace('views.ecommerce.includes.product-specification-value'), [ 'product' => $product, 'attribute' => $attribute, 'currentLangCode' => $currentLangCode, ])
@endforeach
@endforeach @elseif ($visibleAttributes && count($visibleAttributes)) {{-- Flat fallback: no spec table assigned. Render a single un-grouped definition list so the tab still has structure. --}}
@foreach ($visibleAttributes as $attribute)
{{ $attribute->name }}
@include(Theme::getThemeNamespace('views.ecommerce.includes.product-specification-value'), [ 'product' => $product, 'attribute' => $attribute, 'currentLangCode' => $currentLangCode, ])
@endforeach
@endif