Skip to content

Fixed issue #20030 :Customer EAV Decimal Attribute required allow 0 #20130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public function setRequestScope($scope)

/**
* Set scope visibility
*
* Search value only in scope or search value in scope and global
*
* @param bool $flag
Expand Down Expand Up @@ -296,7 +297,7 @@ protected function _applyOutputFilter($value)
* Validate value by attribute input validation rule
*
* @param string $value
* @return string|true
* @return array|true
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
Expand Down
29 changes: 19 additions & 10 deletions app/code/Magento/Eav/Model/Attribute/Data/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,17 @@ public function validateValue($value)
return true;
}

if (empty($value) && $value !== '0') {
if (empty($value) && $value !== '0' && $attribute->getDefaultValue() === null) {
$label = __($attribute->getStoreLabel());
$errors[] = __('"%1" is a required value.', $label);
}

$result = $this->validateLength($attribute, $value);
if (count($result) !== 0) {
$errors = array_merge($errors, $result);
}
$validateLengthResult = $this->validateLength($attribute, $value);
$errors = array_merge($errors, $validateLengthResult);

$validateInputRuleResult = $this->validateInputRule($value);
$errors = array_merge($errors, $validateInputRuleResult);

$result = $this->_validateInputRule($value);
if ($result !== true) {
$errors = array_merge($errors, $result);
}
if (count($errors) == 0) {
return true;
}
Expand Down Expand Up @@ -141,7 +138,7 @@ public function outputValue($format = \Magento\Eav\Model\AttributeDataFactory::O
* @param string $value
* @return array errors
*/
private function validateLength(\Magento\Eav\Model\Attribute $attribute, $value): array
private function validateLength(\Magento\Eav\Model\Attribute $attribute, string $value): array
{
$errors = [];
$length = $this->_string->strlen(trim($value));
Expand All @@ -162,4 +159,16 @@ private function validateLength(\Magento\Eav\Model\Attribute $attribute, $value)

return $errors;
}

/**
* Validate value by attribute input validation rule.
*
* @param string $value
* @return array
*/
private function validateInputRule(string $value): array
{
$result = $this->_validateInputRule($value);
return \is_array($result) ? $result : [];
}
}