-
Notifications
You must be signed in to change notification settings - Fork 29
magento-engcom/import-export-improvements#30: Validation should fail when a required field is supplied but is empty after trimming #113
Conversation
Hi @pogster do you think you can have a look over the travis failures and see if you can solve them? If you have any issues fixing these feel free to drop me a message. |
@@ -593,6 +593,12 @@ protected function _validateRowForUpdate(array $rowData, $rowNumber) | |||
if (in_array($attributeCode, $this->_ignoredAttributes)) { | |||
continue; | |||
} | |||
if ($attributeParams['is_required'] |
There was a problem hiding this comment.
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)
) {
There was a problem hiding this comment.
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.
fefc55d
to
517b7ff
Compare
…ation. Add check if the required attribute is not empty after trimming.
…umn name so several columns in the same row may throw the same error and they can be distinguished.
517b7ff
to
0832e29
Compare
@dmanners managed to. Yaay! I'm impressed by the unit tests actually. |
98f74ef
to
f670792
Compare
Could you also take a look at the static tests:
|
f670792
to
b4ce314
Compare
Yeah my refactoring screwed them up. I will look for something to support the M2 coding standards. And run the functional tests. |
@dmanners it seems the integration tests are timing out? is that a known issue or something? |
@pogster let me check on those timing out tests for you. |
…plied but is empty after trimming #113
Description
As the issue describes, when on customer import the first name or last name are supplied with a whitespace value, validation will not fail as opposed to editing a customer on the backend. The file succeeds to validate and import. This should not be the case. Furthermore, when both first and last name are invalidated, both validation failures should show on the import messages.
As a solution, I moved the required field validation before the attribute validation and added a check for empty strings after trimming.
Additionally, with that solution, only a validation error for the first failed field would show. This is caused by the error code valueIsRequired / line 1 (for example) is used for each field, but the ProcessingErrorAggregator only allows one error of the same code per line. I did not find out in which scenario this would be relevant and removed the code, undoing an earlier commit.
Fixed Issues (if relevant)
Manual testing scenarios
Test data for csv:
Steps to reproduce
Contribution checklist