Skip to content

CatalogImportExport doesn't support empty row values #7468

Closed
@koenner01

Description

@koenner01

If you have an attribute that has a value and you import an empty string because the value needs to be empty, the attribute will not be overwritten with the empty string.

Preconditions

  1. MG2.1.2
  2. PHP7.0

Steps to reproduce

  1. Enter a value for an attribute for a product through the backend of Magento
    (I'm using description as my example)
  2. Create an import csv and leave the column for the attribute blank
  3. Import the csv with Add/Update behaviour

Expected result

  1. Product attribute value should be empty

Actual result

  1. Product attribute keeps the previous value

This issue can be traced back to \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType where the clearEmptyData function unsets all empty rows.

public function clearEmptyData(array $rowData)
{
    foreach ($this->_getProductAttributes($rowData) as $attrCode => $attrParams) {
        if (!$attrParams['is_static'] && empty($rowData[$attrCode])) {
            unset($rowData[$attrCode]);
        }
    }
    return $rowData;
}

It is my opinion that support for empty rows should be allowed.
My suggested fix is adding a constant to the AbstractType class and set the row values that contain that constant value to an empty string. That way if the constant value is used in the import csv, the importer will know which fields are just empty and which fields contain empty values.

CONST EMPTY_ROW_VALUE = '__EMPTY__';

public function clearEmptyData(array $rowData)
{
    foreach ($this->_getProductAttributes($rowData) as $attrCode => $attrParams) {
        if (!$attrParams['is_static'] && empty($rowData[$attrCode])) {
            unset($rowData[$attrCode]);
            continue;
        }

        if ($rowData[$attrCode] === self::EMPTY_ROW_VALUE) {
            $rowData[$attrCode] = '';
        }
    }
    return $rowData;
}

It would be even better to allow for setting custom values for the EMPTY_ROW_VALUE constant through the backend.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: ImportExportIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions