Magento2: Bug product import additional images

Created on 15 Dec 2016  路  9Comments  路  Source: magento/magento2

Import products fails when additional_images uses a value separator different than ","

Preconditions

  1. Magento C.E - 2.3

Steps to reproduce

  1. Create one Product with several images
  2. Go to System -> Export and export all products
  3. Open generated .csv file
  4. Edit additional_images field to separate images using ";" instead.
    additional_images field

  5. Go to `System -> Import``

  6. Edit following configuration: (See screenshot)

    • Allow errors count -> 1
    • Multiple value separator -> ;
    • Images File Directory -> pub/media/catalog/product
  7. Press button Check File

Expected result

File check is successful

Actual result

Error: Wrong url/path used for attribute additional_images
Attached screenshot
import error

ImportExport bug report

All 9 comments

The source of the Bug is the following:

The value used to explode the filename values is different during validation and import steps

Validation Step:

\Magento\CatalogImportExport\Model\Import\Product\Validator\Media
public function isValid($value)
{
   //...
   foreach (explode(self::ADDITIONAL_IMAGES_DELIMITER, $value[self::ADDITIONAL_IMAGES]) as $image) {
   //...
   }
}

Import Step:

\Magento\CatalogImportExport\Model\Import\Product

public function getImagesFromRow(array $rowData)
{
    //...
    $images[$column] = array_unique(
        explode($this->getMultipleValueSeparator(), $rowData[$column])
    );
    //...   
    $labels[$column] = explode($this->getMultipleValueSeparator(), $rowData[$column . '_label']);
    //...   
}

When the Value separator configured for the import is different than "," the validation goes through but the import fails because the value separator used for the explode is not a coma.

Please use the same separator for "additional_images" everywhere.

We also noticed that the separator for the export uses another different constant. From my point of view, here we should also use the same constant.

\Magento\CatalogImportExport\Model\Export\Product

   private function appendMultirowData(&$dataRow, &$multiRawData)
   {

    //...
    $dataRow['additional_images'] = implode(Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $additionalImages);
    $dataRow['additional_image_labels'] = implode(Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $additionalImageLabels);
    //...

   } 

I agree on this one, I was about to import a large file and I was surprised that the additional_images column was not using the same delimiter. Although easy to figure out, to prevent confusion the same Multiple value separator should be used throughout the CSV file.

Yep, got same issue, delimiter for additonal_images is hardcoded => coma. but getImagesFromRow(array $rowData) using $this->getMultipleValueSeparator().

Same issue here, the self::ADDITIONAL_IMAGES_DELIMITER is really causing confusing.

So the interim solution is: in magento/module-catalog-import-export/Model/Import/Product/Validator/Media.php:

Change the hard coded image delimiter to:

    const ADDITIONAL_IMAGES_DELIMITER = '|';

Or rewrite that file

@jalogut Can you propose a solution that get's the multiple value delimiter?

I'm having the same issue in Magento ver. 2.1.4.

My solution was to rewrite the file and edit the

const ADDITIONAL_IMAGES_DELIMITER = '|';

Rewrite in di.xml:

<preference for="Magento\CatalogImportExport\Model\Import\Product\Validator\Media" type="Project\Import\CatalogImportExport\Model\Import\Product\Validator\Media" />

Was this page helpful?
0 / 5 - 0 ratings