Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.
Merged
Changes from 1 commit
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
Next Next commit
#30: Do required attribute check before attribute validation. Add che…
…ck if the required attribute is not empty after trimming.
  • Loading branch information
carstenpfeifer authored and pogster committed Jun 30, 2018
commit a8ee55551ecf13eaeefc665de14145f94bc757aa
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,12 @@ protected function _validateRowForUpdate(array $rowData, $rowNumber)
if (in_array($attributeCode, $this->_ignoredAttributes)) {
continue;
}
if ($attributeParams['is_required']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this way to write? I think it's more readable ^^ Logically it's okay i think.

$attributeCodeNotSetAndNoCustomerId = !isset($rowData[$attributeCode]) && !$this->_getCustomerId($email, $website);
$attributeCodeSetAndValueIsEmptyString = isset($rowData[$attributeCode])  && '' === trim($rowData[$attributeCode]);

if (
    $attributeParams['is_required']
    && ($attributeCodeNotSetAndNoCustomerId || $attributeCodeSetAndValueIsEmptyString)
) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, better readable, do they do that in Magento core nowadays?
Short circuit evaluation might be a reason to not do it.

&& ((!isset($rowData[$attributeCode]) && !$this->_getCustomerId($email, $website))
|| (isset($rowData[$attributeCode]) && '' === trim($rowData[$attributeCode])))) {
$this->addRowError(self::ERROR_VALUE_IS_REQUIRED, $rowNumber, $attributeCode);
continue;
}
if (isset($rowData[$attributeCode]) && strlen($rowData[$attributeCode])) {
$this->isAttributeValid(
$attributeCode,
Expand All @@ -603,8 +609,6 @@ protected function _validateRowForUpdate(array $rowData, $rowNumber)
? $this->_parameters[Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR]
: Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR
);
} elseif ($attributeParams['is_required'] && !$this->_getCustomerId($email, $website)) {
$this->addRowError(self::ERROR_VALUE_IS_REQUIRED, $rowNumber, $attributeCode);
}
}
}
Expand Down