Skip to content

Fixed Importing: non-default multiple value separator can't be used in custom multiple select attribute #31878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
*/
class Product extends AbstractEntity
{
private const DEFAULT_GLOBAL_MULTIPLE_VALUE_SEPARATOR = ',';
public const CONFIG_KEY_PRODUCT_TYPES = 'global/importexport/import_product_types';
private const HASH_ALGORITHM = 'sha256';

Expand Down Expand Up @@ -2841,6 +2842,10 @@ private function parseAttributesWithWrappedValues($attributesData)
public function parseMultiselectValues($values, $delimiter = self::PSEUDO_MULTI_LINE_SEPARATOR)
{
if (empty($this->_parameters[Import::FIELDS_ENCLOSURE])) {
if ($this->getMultipleValueSeparator() !== self::DEFAULT_GLOBAL_MULTIPLE_VALUE_SEPARATOR) {
$delimiter = $this->getMultipleValueSeparator();
}

return explode($delimiter, $values);
}
if (preg_match_all('~"((?:[^"]|"")*)"~', $values, $matches)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,32 @@ public function testProductWithInvalidWeight()
$errors->getErrorByRowNumber(1)[0]->getErrorMessage()
);
}

/**
* Test validate multiselect values with custom separator
*
* @magentoDataFixture Magento/Catalog/_files/products_with_multiselect_attribute.php
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
*
* @return void
*/
public function testValidateMultiselectValuesWithCustomSeparator(): void
{
$pathToFile = __DIR__ . './../_files/products_with_custom_multiselect_values_separator.csv';
$filesystem = $this->objectManager->create(Filesystem::class);
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
$source = $this->objectManager->create(Csv::class, ['file' => $pathToFile, 'directory' => $directory]);
$params = [
'behavior' => Import::BEHAVIOR_ADD_UPDATE,
'entity' => 'catalog_product',
Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR => '|||'
];

$errors = $this->_model->setParameters($params)
->setSource($source)
->validateData();

$this->assertEmpty($errors->getAllErrors());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sku,store_view_code,product_type,name,price,additional_attributes
simple_ms_2,,simple,"With Multiselect 2",10,"multiselect_attribute=Option 2|||Option 3"