diff --git a/src/Export/Adapters/AttributeAdapter.php b/src/Export/Adapters/AttributeAdapter.php index 6ed8759..4a861fa 100644 --- a/src/Export/Adapters/AttributeAdapter.php +++ b/src/Export/Adapters/AttributeAdapter.php @@ -41,6 +41,8 @@ public function adapt(ProductEntity $product): array $optionAttributes = $this->getOptionAttributes($product); $customFieldAttributes = $this->getCustomFieldAttributes($product); $additionalAttributes = $this->getAdditionalAttributes($product); + $seoUrlAttributes = $this->getSeoUrlAttributes($product); + $imageUrlAttributes = $this->getImageUrlAttributes($product); return array_merge( $categoryAttributes, @@ -49,6 +51,8 @@ public function adapt(ProductEntity $product): array $optionAttributes, $customFieldAttributes, $additionalAttributes, + $seoUrlAttributes, + $imageUrlAttributes, ); } @@ -234,6 +238,53 @@ protected function getCustomFieldAttributes(ProductEntity $product): array return $attributes; } + protected function getSeoUrlAttributes(ProductEntity $product): array + { + $attributes = []; + + // Extract SEO URLs from the product + if (!empty($product->seoUrls)) { + foreach ($product->seoUrls as $seoUrl) { + $url = $seoUrl->url; + if (!Utils::isEmpty($url)) { + $cleanedUrl = Utils::cleanString($url); + + $seoUrlAttribute = new Attribute( + 'urls', + $this->decodeHtmlEntities(array_filter((array) $cleanedUrl, 'strlen')) + ); + + $attributes[] = $seoUrlAttribute; + } + } + } + + return $attributes; + } + + protected function getImageUrlAttributes(ProductEntity $product): array + { + $attributes = []; + + if (!empty($product->media)) { + foreach ($product->media as $mediaItem) { + $imageUrl = $mediaItem->media->url ?? null; + if (!Utils::isEmpty($imageUrl)) { + $cleanedUrl = Utils::cleanString($imageUrl); + + $imageUrlAttribute = new Attribute( + 'images', + $this->decodeHtmlEntities(array_filter((array) $cleanedUrl, 'strlen')) + ); + + $attributes[] = $imageUrlAttribute; + } + } + } + + return $attributes; + } + protected function decodeHtmlEntities(array $values): array { foreach ($values as $key => $value) {