-
Notifications
You must be signed in to change notification settings - Fork 9.4k
magento/magento2#14510: Creating custom customer attribute with default value 0 will cause not saving value for customer entity. #16915
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
|
|
||
| namespace Magento\Downloadable\Setup; | ||
|
|
||
| use Magento\Eav\Setup\EavSetup; | ||
| use Magento\Eav\Setup\EavSetupFactory; | ||
| use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
| use Magento\Framework\Setup\UpgradeDataInterface; | ||
| use Magento\Framework\Setup\ModuleContextInterface; | ||
|
|
||
| /** | ||
| * @codeCoverageIgnore | ||
| */ | ||
| class UpgradeData implements UpgradeDataInterface | ||
| { | ||
| /** | ||
| * EAV setup factory | ||
| * | ||
| * @var EavSetupFactory | ||
| */ | ||
| private $eavSetupFactory; | ||
|
|
||
| /** | ||
| * Init | ||
| * | ||
| * @param EavSetupFactory $eavSetupFactory | ||
| */ | ||
| public function __construct(EavSetupFactory $eavSetupFactory) | ||
| { | ||
| $this->eavSetupFactory = $eavSetupFactory; | ||
| } | ||
|
|
||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) | ||
| { | ||
| $setup->startSetup(); | ||
|
|
||
| if (version_compare($context->getVersion(), '2.0.3', '<')) { | ||
| /** @var EavSetup $eavSetup */ | ||
| $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); | ||
| // remove default value | ||
| $eavSetup->updateAttribute( | ||
| \Magento\Catalog\Model\Product::ENTITY, | ||
| 'links_exist', | ||
| 'default_value', | ||
| null | ||
| ); | ||
| } | ||
|
|
||
| $setup->endSetup(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -203,12 +203,12 @@ public function getEntityValueId($entity) | |
| /** | ||
| * Retrieve default value | ||
| * | ||
| * @return mixed | ||
| * @return string | ||
| */ | ||
| public function getDefaultValue() | ||
| { | ||
| if ($this->_defaultValue === null) { | ||
| if ($this->getAttribute()->getDefaultValue()) { | ||
| if ($this->getAttribute()->getDefaultValue() !== null) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you touch the logic that relates to all attributes. Are you sure that all other attributes have
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @slavvka, I have two arguments for this point. |
||
| $this->_defaultValue = $this->getAttribute()->getDefaultValue(); | ||
| } else { | ||
| $this->_defaultValue = ""; | ||
|
|
@@ -280,7 +280,7 @@ public function afterLoad($object) | |
| public function beforeSave($object) | ||
| { | ||
| $attrCode = $this->getAttribute()->getAttributeCode(); | ||
| if (!$object->hasData($attrCode) && $this->getDefaultValue()) { | ||
| if (!$object->hasData($attrCode) && $this->getDefaultValue() !== '') { | ||
| $object->setData($attrCode, $this->getDefaultValue()); | ||
| } | ||
|
|
||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.