> */ public function getFields(int $productId, array $targetStoreIds = []): array { $sourceProduct = $this->productRepository->getById($productId, false, $this->config->getSourceStoreId()); $targetProduct = $targetStoreIds !== [] ? $this->productRepository->getById($productId, false, (int)reset($targetStoreIds)) : null; $fields = []; foreach ($this->getAttributes() as $attribute) { $code = (string)$attribute->getAttributeCode(); $sourceValue = (string)($sourceProduct->getData($code) ?? ''); $targetValue = $targetProduct ? (string)($targetProduct->getData($code) ?? '') : ''; $fields[] = [ 'code' => $code, 'label' => (string)$attribute->getDefaultFrontendLabel() ?: $code, 'source_value' => $sourceValue, 'target_value' => $targetValue, 'is_html' => $this->isHtmlAttribute($attribute), ]; } return $fields; } /** * @return Attribute[] */ public function getAttributes(): array { $attributes = []; foreach ($this->config->getTranslatableAttributeCodes() as $code) { try { $attribute = $this->attributeRepository->get($code); } catch (\Throwable) { continue; } if (!$attribute instanceof Attribute) { continue; } if (!in_array((string)$attribute->getFrontendInput(), ['text', 'textarea'], true)) { continue; } if ($attribute->isScopeGlobal()) { continue; } $attributes[$code] = $attribute; } return array_values($attributes); } public function isAttributeAllowed(string $code): bool { foreach ($this->getAttributes() as $attribute) { if ((string)$attribute->getAttributeCode() === $code) { return true; } } return false; } public function isHtmlAttributeCode(string $code): bool { foreach ($this->getAttributes() as $attribute) { if ((string)$attribute->getAttributeCode() === $code) { return $this->isHtmlAttribute($attribute); } } return false; } private function isHtmlAttribute(Attribute $attribute): bool { return (bool)$attribute->getIsWysiwygEnabled() || in_array((string)$attribute->getAttributeCode(), ['description', 'short_description'], true); } }