attribute ?? null) ? $this->attribute : []; $values = is_array($this->values ?? null) ? $this->values : []; $languages = is_array($this->languages ?? null) ? $this->languages : []; $defaultLanguageId = (string)($this->defaultLanguageId ?? ''); $activeLanguages = []; foreach ($languages as $language) { if ((int)($language['status'] ?? 0) === 1) { $activeLanguages[] = $language; } } if ($defaultLanguageId === '' && !empty($activeLanguages[0]['id'])) { $defaultLanguageId = (string)$activeLanguages[0]['id']; } $attributeName = ''; if ($defaultLanguageId !== '' && isset($attribute['languages'][$defaultLanguageId]['name'])) { $attributeName = trim((string)$attribute['languages'][$defaultLanguageId]['name']); } if ($attributeName === '' && is_array($attribute['languages'] ?? null)) { foreach ($attribute['languages'] as $languageData) { $candidateName = trim((string)($languageData['name'] ?? '')); if ($candidateName !== '') { $attributeName = $candidateName; break; } } } if ($attributeName === '') { $attributeName = 'ID: ' . (int)($attribute['id'] ?? 0); } $rowCounter = 0; $initialRowsHtml = ''; if (!empty($values)) { foreach ($values as $value) { ++$rowCounter; $rowKey = 'existing-' . (int)($value['id'] ?? 0); $initialRowsHtml .= \Shared\Tpl\Tpl::view('shop-attribute/_partials/value-row', [ 'rowKey' => $rowKey, 'value' => $value, 'languages' => $activeLanguages, 'defaultLanguageId' => $defaultLanguageId, ]); } } else { $rowCounter = 1; $initialRowsHtml .= \Shared\Tpl\Tpl::view('shop-attribute/_partials/value-row', [ 'rowKey' => 'new-1', 'value' => ['id' => 0, 'is_default' => 1, 'impact_on_the_price' => null, 'languages' => []], 'languages' => $activeLanguages, 'defaultLanguageId' => $defaultLanguageId, ]); } $newRowTemplate = \Shared\Tpl\Tpl::view('shop-attribute/_partials/value-row', [ 'rowKey' => '__ROW_KEY__', 'value' => ['id' => 0, 'is_default' => 0, 'impact_on_the_price' => null, 'languages' => []], 'languages' => $activeLanguages, 'defaultLanguageId' => $defaultLanguageId, ]); ?>