From 2a5ddc740bbe7f3ad6b7a9c27b44d385f42f88ce Mon Sep 17 00:00:00 2001 From: robertsaternus Date: Fri, 15 Nov 2024 16:14:36 +0100 Subject: [PATCH] FFWEB-3224: Example how to export variants names --- src/Export/Data/Entity/ProductEntity.php | 7 ++++++- src/Export/Data/Entity/ProductEntityInterface.php | 1 + src/Export/Data/Entity/VariantEntity.php | 7 ++++++- src/Resources/config/services.xml | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Export/Data/Entity/ProductEntity.php b/src/Export/Data/Entity/ProductEntity.php index ab4a3dd1..4d25b748 100644 --- a/src/Export/Data/Entity/ProductEntity.php +++ b/src/Export/Data/Entity/ProductEntity.php @@ -57,6 +57,11 @@ public function getProductNumber(): string return $this->product->getProductNumber(); } + public function getProductName(): string + { + return (string) $this->product->getTranslation('name'); + } + public function getFilterAttributes(): string { return $this->filterAttributes; @@ -100,7 +105,7 @@ public function toArray(): array $defaultFields = [ 'ProductNumber' => $this->product->getProductNumber(), 'Master' => $isVariant ? $this->parent->getProductNumber() : $this->product->getProductNumber(), - 'Name' => (string) $this->product->getTranslation('name'), + 'Name' => $this->getProductName(), 'FilterAttributes' => $this->getFilterAttributes(), 'CustomFields' => $this->getCustomFields(), ]; diff --git a/src/Export/Data/Entity/ProductEntityInterface.php b/src/Export/Data/Entity/ProductEntityInterface.php index e155b18d..342404a0 100644 --- a/src/Export/Data/Entity/ProductEntityInterface.php +++ b/src/Export/Data/Entity/ProductEntityInterface.php @@ -7,4 +7,5 @@ interface ProductEntityInterface { public function getProductNumber(): string; + public function getProductName(): string; } diff --git a/src/Export/Data/Entity/VariantEntity.php b/src/Export/Data/Entity/VariantEntity.php index a21ed53f..6c45d892 100644 --- a/src/Export/Data/Entity/VariantEntity.php +++ b/src/Export/Data/Entity/VariantEntity.php @@ -42,9 +42,14 @@ public function getProductNumber(): string return $this->product->getProductNumber(); } + public function getProductName(): string + { + return $this->product->getTranslation('name') ? (string) $this->product->getTranslation('name') : $this->parentData['Name']; + } + public function toArray(): array { $opts = '|' . implode('|', map($this->propertyFormatter, $this->product->getOptions()->getElements())) . '|'; - return array_reduce($this->variantFields, fn (array $fields, FieldInterface $field): array => [$field->getName() => $field->getValue($this->product)] + $fields, ['ProductNumber' => $this->product->getProductNumber(), 'FilterAttributes' => $opts] + $this->parentData); + return array_reduce($this->variantFields, fn (array $fields, FieldInterface $field): array => [$field->getName() => $field->getValue($this->product)] + $fields, ['ProductNumber' => $this->product->getProductNumber(), 'Name' => $this->getProductName(), 'FilterAttributes' => $opts] + $this->parentData); } } diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index a35b8cd4..baa1a0d2 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -46,6 +46,7 @@ children.media + children.translations CategoryPath