Skip to content

Commit 5fa4d5f

Browse files
author
al.kravchuk
committed
#14510: Creating custom customer attribute with default value 0 will cause not saving value for customer entity.
- fix default value check in case of type conversion; - add boolean attribute default value assignment;
1 parent 78ca274 commit 5fa4d5f

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Boolean.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public function beforeSave($object)
2525
$attributeCode = $this->getAttribute()->getName();
2626
if ($object->getData('use_config_' . $attributeCode)) {
2727
$object->setData($attributeCode, BooleanSource::VALUE_USE_CONFIG);
28+
return $this;
2829
}
29-
return $this;
30+
31+
return parent::beforeSave($object);
3032
}
3133
}

app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public function getIsVisibleOnFront()
383383
}
384384

385385
/**
386-
* @return string|int|bool|float
386+
* @return string|null
387387
* @codeCoverageIgnore
388388
*/
389389
public function getDefaultValue()

app/code/Magento/Eav/Model/Entity/Attribute/Backend/AbstractBackend.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@ public function getEntityValueId($entity)
203203
/**
204204
* Retrieve default value
205205
*
206-
* @return mixed
206+
* @return string
207207
*/
208208
public function getDefaultValue()
209209
{
210210
if ($this->_defaultValue === null) {
211-
if ($this->getAttribute()->getDefaultValue()) {
211+
if ($this->getAttribute()->getDefaultValue() !== null) {
212212
$this->_defaultValue = $this->getAttribute()->getDefaultValue();
213213
} else {
214214
$this->_defaultValue = "";
@@ -280,7 +280,7 @@ public function afterLoad($object)
280280
public function beforeSave($object)
281281
{
282282
$attrCode = $this->getAttribute()->getAttributeCode();
283-
if (!$object->hasData($attrCode) && $this->getDefaultValue()) {
283+
if (!$object->hasData($attrCode) && $this->getDefaultValue() !== '') {
284284
$object->setData($attrCode, $this->getDefaultValue());
285285
}
286286

0 commit comments

Comments
 (0)