Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
58 changes: 58 additions & 0 deletions app/code/Magento/Downloadable/Setup/UpgradeData.php
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();
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Downloadable/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_Downloadable" setup_version="2.0.2">
<module name="Magento_Downloadable" setup_version="2.0.3">
<sequence>
<module name="Magento_Catalog"/>
</sequence>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public function getIsVisibleOnFront()
}

/**
* @return string|int|bool|float
* @return string|null
* @codeCoverageIgnore
*/
public function getDefaultValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The 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 null as default value? Won't it break their work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @slavvka,

I have two arguments for this point.
First: auto tests have passed successfully.
Second: if you look at the screenshot under, there are list of attributes with default value '0'. After smoke check I have not found strict check '===' with null or 0 values anymore (exception - 'links_exist' attribute).
So, I assume, there should not be any problems for existing set of attributes.
P.S. have checked on Open Source Magento.
image

$this->_defaultValue = $this->getAttribute()->getDefaultValue();
} else {
$this->_defaultValue = "";
Expand Down Expand Up @@ -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());
}

Expand Down