Skip to content

Commit 2e08782

Browse files
ENGCOM-8819: Fixed Importing: non-default multiple value separator can't be used in custom multiple select attribute #31878
- Merge Pull Request #31878 from engcom-Charlie/magento2:23156 - Merged commits: 1. 15ccdfd 2. a749903 3. b07f7c0 4. 8d72601 5. 2664d7e 6. f2eec91 7. 7f00bbe
2 parents 86dc050 + 7f00bbe commit 2e08782

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
*/
4848
class Product extends AbstractEntity
4949
{
50+
private const DEFAULT_GLOBAL_MULTIPLE_VALUE_SEPARATOR = ',';
5051
public const CONFIG_KEY_PRODUCT_TYPES = 'global/importexport/import_product_types';
5152
private const HASH_ALGORITHM = 'sha256';
5253

@@ -2826,6 +2827,10 @@ private function parseAttributesWithWrappedValues($attributesData)
28262827
public function parseMultiselectValues($values, $delimiter = self::PSEUDO_MULTI_LINE_SEPARATOR)
28272828
{
28282829
if (empty($this->_parameters[Import::FIELDS_ENCLOSURE])) {
2830+
if ($this->getMultipleValueSeparator() !== self::DEFAULT_GLOBAL_MULTIPLE_VALUE_SEPARATOR) {
2831+
$delimiter = $this->getMultipleValueSeparator();
2832+
}
2833+
28292834
return explode($delimiter, $values);
28302835
}
28312836
if (preg_match_all('~"((?:[^"]|"")*)"~', $values, $matches)) {

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest/ProductValidationTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,32 @@ public function testProductWithInvalidWeight()
373373
$errors->getErrorByRowNumber(1)[0]->getErrorMessage()
374374
);
375375
}
376+
377+
/**
378+
* Test validate multiselect values with custom separator
379+
*
380+
* @magentoDataFixture Magento/Catalog/_files/products_with_multiselect_attribute.php
381+
* @magentoAppIsolation enabled
382+
* @magentoDbIsolation enabled
383+
*
384+
* @return void
385+
*/
386+
public function testValidateMultiselectValuesWithCustomSeparator(): void
387+
{
388+
$pathToFile = __DIR__ . './../_files/products_with_custom_multiselect_values_separator.csv';
389+
$filesystem = $this->objectManager->create(Filesystem::class);
390+
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
391+
$source = $this->objectManager->create(Csv::class, ['file' => $pathToFile, 'directory' => $directory]);
392+
$params = [
393+
'behavior' => Import::BEHAVIOR_ADD_UPDATE,
394+
'entity' => 'catalog_product',
395+
Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR => '|||'
396+
];
397+
398+
$errors = $this->_model->setParameters($params)
399+
->setSource($source)
400+
->validateData();
401+
402+
$this->assertEmpty($errors->getAllErrors());
403+
}
376404
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku,store_view_code,product_type,name,price,additional_attributes
2+
simple_ms_2,,simple,"With Multiselect 2",10,"multiselect_attribute=Option 2|||Option 3"

0 commit comments

Comments
 (0)