@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