From 4da14ca0da3881c0245fcb68361f611fef212bc3 Mon Sep 17 00:00:00 2001 From: "al.kravchuk" Date: Wed, 18 Jul 2018 19:41:47 +0300 Subject: [PATCH 1/4] Creating custom customer attribute with default value 0 will --- .../Catalog/Model/Product/Attribute/Backend/Boolean.php | 4 +++- .../Eav/Model/Entity/Attribute/AbstractAttribute.php | 4 +--- .../Eav/Model/Entity/Attribute/Backend/AbstractBackend.php | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Boolean.php b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Boolean.php index c2108b0273bdb..dbefb09f06bd1 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Boolean.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Boolean.php @@ -25,7 +25,9 @@ public function beforeSave($object) $attributeCode = $this->getAttribute()->getName(); if ($object->getData('use_config_' . $attributeCode)) { $object->setData($attributeCode, BooleanSource::VALUE_USE_CONFIG); + return $this; } - return $this; + + return parent::beforeSave($object); } } diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php b/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php index 29ead9ff810e5..b545092e62244 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php @@ -416,9 +416,7 @@ public function getIsVisibleOnFront() } /** - * Returns default value - * - * @return string|int|bool|float + * @return string|null * @codeCoverageIgnore */ public function getDefaultValue() diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/AbstractBackend.php b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/AbstractBackend.php index 53c32e1cbfba4..14788bf15473e 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/AbstractBackend.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/AbstractBackend.php @@ -204,12 +204,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) { $this->_defaultValue = $this->getAttribute()->getDefaultValue(); } else { $this->_defaultValue = ""; @@ -285,7 +285,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()); } From 1e32ea6dcbd1f24c62e0614ffd46946ea1ffa6f4 Mon Sep 17 00:00:00 2001 From: "al.kravchuk" Date: Sun, 22 Jul 2018 00:12:09 +0300 Subject: [PATCH 2/4] =?UTF-8?q?Creating=20custom=20customer=20attribute=20?= =?UTF-8?q?with=20default=20value=200=20will=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Downloadable/Setup/UpgradeData.php | 58 +++++++++++++++++++ app/code/Magento/Downloadable/etc/module.xml | 2 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/Downloadable/Setup/UpgradeData.php diff --git a/app/code/Magento/Downloadable/Setup/UpgradeData.php b/app/code/Magento/Downloadable/Setup/UpgradeData.php new file mode 100644 index 0000000000000..0f509ed32cbf2 --- /dev/null +++ b/app/code/Magento/Downloadable/Setup/UpgradeData.php @@ -0,0 +1,58 @@ +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(); + } +} diff --git a/app/code/Magento/Downloadable/etc/module.xml b/app/code/Magento/Downloadable/etc/module.xml index 72aadff621eca..fb13121335730 100644 --- a/app/code/Magento/Downloadable/etc/module.xml +++ b/app/code/Magento/Downloadable/etc/module.xml @@ -6,7 +6,7 @@ */ --> - + From a77d8666f86f9817b6861b4facb88bd93e53dff7 Mon Sep 17 00:00:00 2001 From: "al.kravchuk" Date: Fri, 5 Oct 2018 09:56:25 +0300 Subject: [PATCH 3/4] magento/magento2#14510: Creating custom customer attribute with default value 0 will cause not saving value for customer entity. Remove curly braces. --- app/code/Magento/Downloadable/Setup/UpgradeData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Downloadable/Setup/UpgradeData.php b/app/code/Magento/Downloadable/Setup/UpgradeData.php index 0f509ed32cbf2..aec15ce7f9d90 100644 --- a/app/code/Magento/Downloadable/Setup/UpgradeData.php +++ b/app/code/Magento/Downloadable/Setup/UpgradeData.php @@ -35,7 +35,7 @@ public function __construct(EavSetupFactory $eavSetupFactory) } /** - * {@inheritdoc} + * @inheritdoc */ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { From 9524c1d063756a99723e9804755d0fc1e102a2b2 Mon Sep 17 00:00:00 2001 From: vgelani Date: Thu, 1 Nov 2018 18:04:55 +0530 Subject: [PATCH 4/4] Removed upgrade data file --- .../Data/InstallDownloadableAttributes.php | 2 +- .../Downloadable/Setup/UpgradeData.php | 58 ------------------- app/code/Magento/Downloadable/etc/module.xml | 2 +- 3 files changed, 2 insertions(+), 60 deletions(-) delete mode 100644 app/code/Magento/Downloadable/Setup/UpgradeData.php diff --git a/app/code/Magento/Downloadable/Setup/Patch/Data/InstallDownloadableAttributes.php b/app/code/Magento/Downloadable/Setup/Patch/Data/InstallDownloadableAttributes.php index 9c101425e49ae..da1bf47f0f7f3 100644 --- a/app/code/Magento/Downloadable/Setup/Patch/Data/InstallDownloadableAttributes.php +++ b/app/code/Magento/Downloadable/Setup/Patch/Data/InstallDownloadableAttributes.php @@ -142,7 +142,7 @@ public function apply() 'visible' => false, 'required' => false, 'user_defined' => false, - 'default' => '0', + 'default' => null, 'searchable' => false, 'filterable' => false, 'comparable' => false, diff --git a/app/code/Magento/Downloadable/Setup/UpgradeData.php b/app/code/Magento/Downloadable/Setup/UpgradeData.php deleted file mode 100644 index aec15ce7f9d90..0000000000000 --- a/app/code/Magento/Downloadable/Setup/UpgradeData.php +++ /dev/null @@ -1,58 +0,0 @@ -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(); - } -} diff --git a/app/code/Magento/Downloadable/etc/module.xml b/app/code/Magento/Downloadable/etc/module.xml index fb13121335730..99c6e5e1cc49c 100644 --- a/app/code/Magento/Downloadable/etc/module.xml +++ b/app/code/Magento/Downloadable/etc/module.xml @@ -6,7 +6,7 @@ */ --> - +