From 7302b15684cdf0d962631a0605a09930efa3f9a5 Mon Sep 17 00:00:00 2001 From: Thomas Neumann Date: Thu, 30 Aug 2018 13:31:43 +0200 Subject: [PATCH 1/3] Allow unsetting text collection values on mass edit / import --- .../ValueConverter/TextCollectionConverter.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ArrayConverter/FlatToStandard/Product/ValueConverter/TextCollectionConverter.php b/src/ArrayConverter/FlatToStandard/Product/ValueConverter/TextCollectionConverter.php index 3e2fe51..45b4d92 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, ]], ]; } From 307aab2c8298bd2a5637a2949b7a807e24bfd3d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20M=C3=A9tayer?= Date: Mon, 3 Sep 2018 13:37:24 +0200 Subject: [PATCH 2/3] Update integration test --- Tests/Integration/Job/ImportTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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()); } } From 049da87bdd74f84e21364109b8bfa149d0288d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20M=C3=A9tayer?= Date: Mon, 3 Sep 2018 13:39:18 +0200 Subject: [PATCH 3/3] Use single quotes --- .../Product/ValueConverter/TextCollectionConverter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArrayConverter/FlatToStandard/Product/ValueConverter/TextCollectionConverter.php b/src/ArrayConverter/FlatToStandard/Product/ValueConverter/TextCollectionConverter.php index 45b4d92..c5157d3 100644 --- a/src/ArrayConverter/FlatToStandard/Product/ValueConverter/TextCollectionConverter.php +++ b/src/ArrayConverter/FlatToStandard/Product/ValueConverter/TextCollectionConverter.php @@ -58,7 +58,7 @@ public function supportsField($attributeType) public function convert(array $attributeFieldInfo, $value) { $trimmedValue = trim($value); - if ("" === $trimmedValue) { + if ('' === $trimmedValue) { $data = []; } else { $data = array_map(