diff --git a/src/Export/Adapters/AttributeAdapter.php b/src/Export/Adapters/AttributeAdapter.php index 6ed8759..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 { @@ -223,11 +224,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')), + ); + } } } diff --git a/tests/Export/Adapters/AttributeAdapterTest.php b/tests/Export/Adapters/AttributeAdapterTest.php index 7d9fc14..ba6e150 100644 --- a/tests/Export/Adapters/AttributeAdapterTest.php +++ b/tests/Export/Adapters/AttributeAdapterTest.php @@ -19,6 +19,9 @@ use PHPUnit\Framework\TestCase; use ReflectionClass; use Vin\ShopwareSdk\Data\Uuid\Uuid; +use Shopware\Core\Defaults; +use Shopware\Core\Framework\DataAbstractionLayer\Pricing\Price; +use Shopware\Core\Framework\DataAbstractionLayer\Pricing\PriceCollection; class AttributeAdapterTest extends TestCase { @@ -750,4 +753,34 @@ public function categoryAndCatUrlWithIntegrationTypeProvider(): array ], ]; } + + public function priceCustomFieldProvider(): array + { + return [ + 'CustomFieldCollectionWithPrice' => [ + 'customFields' => [ + 'price' => [ + 'net' => 22, + 'grose' => 21, + ], + ], + ], + ]; + } + + /** + * @dataProvider priceCustomFieldProvider + */ + public function testPriceCustomField(array $customFields): void + { + $price = new PriceCollection([new Price(Defaults::CURRENCY, 0, 0, false)]); + + $data['customFields'] = $customFields; + $productEntity = $this->createTestProduct($data, true); +// $attributes = $this->attributeAdapter->adapt($productEntity); +// $customFieldAttributes = $this->getCustomFields($attributes, $data); + + $this->assertSame(true, true); + } + }