diff --git a/Tests/Integration/Job/ImportTest.php b/Tests/Integration/Job/ImportTest.php index a7d8302..e0e23f1 100644 --- a/Tests/Integration/Job/ImportTest.php +++ b/Tests/Integration/Job/ImportTest.php @@ -136,6 +136,6 @@ public function testImportCanUpdateProducts() $thirdSku = $cursor->current(); $this->assertInstanceOf(ProductInterface::class, $thirdSku); - $this->assertCount(2, $thirdSku->getValue('my_text_collection', 'en_US')->getData()); + $this->assertCount(0, $thirdSku->getValue('my_text_collection', 'en_US')->getData()); } } diff --git a/src/ArrayConverter/FlatToStandard/Product/ValueConverter/TextCollectionConverter.php b/src/ArrayConverter/FlatToStandard/Product/ValueConverter/TextCollectionConverter.php index 3e2fe51..c5157d3 100644 --- a/src/ArrayConverter/FlatToStandard/Product/ValueConverter/TextCollectionConverter.php +++ b/src/ArrayConverter/FlatToStandard/Product/ValueConverter/TextCollectionConverter.php @@ -57,15 +57,21 @@ public function supportsField($attributeType) */ public function convert(array $attributeFieldInfo, $value) { - if ('' === trim($value)) { - return []; + $trimmedValue = trim($value); + if ('' === $trimmedValue) { + $data = []; + } else { + $data = array_map( + 'trim', + explode(TextCollectionType::FLAT_SEPARATOR, $trimmedValue) + ); } return [ $attributeFieldInfo['attribute']->getCode() => [[ 'locale' => $attributeFieldInfo['locale_code'], 'scope' => $attributeFieldInfo['scope_code'], - 'data' => explode(TextCollectionType::FLAT_SEPARATOR, $value), + 'data' => $data, ]], ]; }