From a5c979b22bb2a290cb7ec8a00698b1835b6e7f4c Mon Sep 17 00:00:00 2001 From: nenadj-soprex Date: Mon, 23 Oct 2023 12:40:34 +0200 Subject: [PATCH 1/3] Logic for custom price field in export --- src/Export/Adapters/AttributeAdapter.php | 25 +++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Export/Adapters/AttributeAdapter.php b/src/Export/Adapters/AttributeAdapter.php index 6ed8759..876cb46 100644 --- a/src/Export/Adapters/AttributeAdapter.php +++ b/src/Export/Adapters/AttributeAdapter.php @@ -223,11 +223,26 @@ protected function getCustomFieldAttributes(ProductEntity $product): array } // Filter null, false and empty strings, but not "0". See: https://stackoverflow.com/a/27501297/6281648 - $customFieldAttribute = new Attribute( - $key, - $this->decodeHtmlEntities(array_filter((array) $cleanedValue, 'strlen')), - ); - $attributes[] = $customFieldAttribute; + if ($cleanedValue instanceof PriceCollection) { + $price = current($cleanedValue->getElements()); + $attributes[] = new Attribute( + $key . '_net', + array_filter((array)$price->getNet(), 'strlen'), + ); + $attributes[] = new Attribute( + $key . '_gross', + array_filter((array)$price->getGross(), 'strlen'), + ); + $attributes[] = new Attribute( + $key . '_curency_id', + array_filter((array)$price->getCurrencyId(), 'strlen'), + ); + } else { + $attributes[] = new Attribute( + $key, + $this->decodeHtmlEntities(array_filter((array) $cleanedValue, 'strlen')), + ); + } } } From e1a12a12931eec0362937e61b26cd92c7b1a2de4 Mon Sep 17 00:00:00 2001 From: nenadj-soprex Date: Wed, 25 Oct 2023 15:19:26 +0200 Subject: [PATCH 2/3] Spaces added after array cast --- src/Export/Adapters/AttributeAdapter.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Export/Adapters/AttributeAdapter.php b/src/Export/Adapters/AttributeAdapter.php index 876cb46..73bf37b 100644 --- a/src/Export/Adapters/AttributeAdapter.php +++ b/src/Export/Adapters/AttributeAdapter.php @@ -227,15 +227,15 @@ protected function getCustomFieldAttributes(ProductEntity $product): array $price = current($cleanedValue->getElements()); $attributes[] = new Attribute( $key . '_net', - array_filter((array)$price->getNet(), 'strlen'), + array_filter((array) $price->getNet(), 'strlen'), ); $attributes[] = new Attribute( $key . '_gross', - array_filter((array)$price->getGross(), 'strlen'), + array_filter((array) $price->getGross(), 'strlen'), ); $attributes[] = new Attribute( $key . '_curency_id', - array_filter((array)$price->getCurrencyId(), 'strlen'), + array_filter((array) $price->getCurrencyId(), 'strlen'), ); } else { $attributes[] = new Attribute( From a59909fdc6b0dd88dcc25b1715b11f0593128392 Mon Sep 17 00:00:00 2001 From: nenadj-soprex Date: Wed, 25 Oct 2023 15:24:21 +0200 Subject: [PATCH 3/3] Add use statement for PriceCollection --- src/Export/Adapters/AttributeAdapter.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Export/Adapters/AttributeAdapter.php b/src/Export/Adapters/AttributeAdapter.php index 73bf37b..62b05a6 100644 --- a/src/Export/Adapters/AttributeAdapter.php +++ b/src/Export/Adapters/AttributeAdapter.php @@ -17,6 +17,7 @@ use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity; use Vin\ShopwareSdk\Data\Entity\PropertyGroupOption\PropertyGroupOptionCollection; use Vin\ShopwareSdk\Data\Entity\PropertyGroupOption\PropertyGroupOptionEntity; +use Shopware\Core\Framework\DataAbstractionLayer\Pricing\PriceCollection; class AttributeAdapter {