Skip to content

Commit c3ef7b0

Browse files
author
Stanislav Idolov
authored
ENGCOM-2237: magento-engcom/import-export-improvements#30: Validation should fail when a required field is supplied but is empty after trimming #113
2 parents ac0c755 + 795d6a4 commit c3ef7b0

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

app/code/Magento/CustomerImportExport/Model/Import/Customer.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,18 @@ protected function _validateRowForUpdate(array $rowData, $rowNumber)
593593
if (in_array($attributeCode, $this->_ignoredAttributes)) {
594594
continue;
595595
}
596+
597+
$isFieldRequired = $attributeParams['is_required'];
598+
$isFieldNotSetAndCustomerDoesNotExist =
599+
!isset($rowData[$attributeCode]) && !$this->_getCustomerId($email, $website);
600+
$isFieldSetAndTrimmedValueIsEmpty
601+
= isset($rowData[$attributeCode]) && '' === trim($rowData[$attributeCode]);
602+
603+
if ($isFieldRequired && ($isFieldNotSetAndCustomerDoesNotExist || $isFieldSetAndTrimmedValueIsEmpty)) {
604+
$this->addRowError(self::ERROR_VALUE_IS_REQUIRED, $rowNumber, $attributeCode);
605+
continue;
606+
}
607+
596608
if (isset($rowData[$attributeCode]) && strlen($rowData[$attributeCode])) {
597609
$this->isAttributeValid(
598610
$attributeCode,
@@ -603,8 +615,6 @@ protected function _validateRowForUpdate(array $rowData, $rowNumber)
603615
? $this->_parameters[Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR]
604616
: Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR
605617
);
606-
} elseif ($attributeParams['is_required'] && !$this->_getCustomerId($email, $website)) {
607-
$this->addRowError(self::ERROR_VALUE_IS_REQUIRED, $rowNumber, $attributeCode);
608618
}
609619
}
610620
}

app/code/Magento/ImportExport/Model/Import/ErrorProcessing/ProcessingErrorAggregator.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function addError(
7777
$errorMessage = null,
7878
$errorDescription = null
7979
) {
80-
if ($this->isErrorAlreadyAdded($rowNumber, $errorCode)) {
80+
if ($this->isErrorAlreadyAdded($rowNumber, $errorCode, $columnName)) {
8181
return $this;
8282
}
8383
$this->processErrorStatistics($errorLevel);
@@ -333,13 +333,14 @@ public function clear()
333333
/**
334334
* @param int $rowNum
335335
* @param string $errorCode
336+
* @param string $columnName
336337
* @return bool
337338
*/
338-
protected function isErrorAlreadyAdded($rowNum, $errorCode)
339+
protected function isErrorAlreadyAdded($rowNum, $errorCode, $columnName = null)
339340
{
340341
$errors = $this->getErrorsByCode([$errorCode]);
341342
foreach ($errors as $error) {
342-
if ($rowNum == $error->getRowNumber()) {
343+
if ($rowNum == $error->getRowNumber() && $columnName == $error->getColumnName()) {
343344
return true;
344345
}
345346
}

0 commit comments

Comments
 (0)