Skip to content

Commit c6d181b

Browse files
authored
ENGCOM-3609: Fixed fatal error if upgrading from Magento v2.0.0 to v2.3 and non system attributes missing #19530
2 parents 84826f9 + 1ca2624 commit c6d181b

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

app/code/Magento/ConfigurableProduct/Setup/Patch/Data/InstallInitialConfigurableAttributes.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66

77
namespace Magento\ConfigurableProduct\Setup\Patch\Data;
88

9+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
910
use Magento\Eav\Setup\EavSetup;
1011
use Magento\Eav\Setup\EavSetupFactory;
11-
use Magento\Framework\App\ResourceConnection;
1212
use Magento\Framework\Setup\ModuleDataSetupInterface;
1313
use Magento\Framework\Setup\Patch\DataPatchInterface;
1414
use Magento\Framework\Setup\Patch\PatchVersionInterface;
15-
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1615

1716
/**
1817
* Class InstallInitialConfigurableAttributes
18+
*
1919
* @package Magento\ConfigurableProduct\Setup\Patch
2020
*/
2121
class InstallInitialConfigurableAttributes implements DataPatchInterface, PatchVersionInterface
@@ -24,6 +24,7 @@ class InstallInitialConfigurableAttributes implements DataPatchInterface, PatchV
2424
* @var ModuleDataSetupInterface
2525
*/
2626
private $moduleDataSetup;
27+
2728
/**
2829
* @var EavSetupFactory
2930
*/
@@ -43,7 +44,7 @@ public function __construct(
4344
}
4445

4546
/**
46-
* {@inheritdoc}
47+
* @inheritdoc
4748
*/
4849
public function apply()
4950
{
@@ -64,40 +65,43 @@ public function apply()
6465
'color'
6566
];
6667
foreach ($attributes as $attributeCode) {
67-
$relatedProductTypes = explode(
68-
',',
69-
$eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode, 'apply_to')
70-
);
71-
if (!in_array(Configurable::TYPE_CODE, $relatedProductTypes)) {
72-
$relatedProductTypes[] = Configurable::TYPE_CODE;
73-
$eavSetup->updateAttribute(
74-
\Magento\Catalog\Model\Product::ENTITY,
75-
$attributeCode,
76-
'apply_to',
77-
implode(',', $relatedProductTypes)
68+
$attribute = $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode, 'apply_to');
69+
if ($attribute) {
70+
$relatedProductTypes = explode(
71+
',',
72+
$attribute
7873
);
74+
if (!in_array(Configurable::TYPE_CODE, $relatedProductTypes)) {
75+
$relatedProductTypes[] = Configurable::TYPE_CODE;
76+
$eavSetup->updateAttribute(
77+
\Magento\Catalog\Model\Product::ENTITY,
78+
$attributeCode,
79+
'apply_to',
80+
implode(',', $relatedProductTypes)
81+
);
82+
}
7983
}
8084
}
8185
}
8286

8387
/**
84-
* {@inheritdoc}
88+
* @inheritdoc
8589
*/
8690
public static function getDependencies()
8791
{
8892
return [];
8993
}
9094

9195
/**
92-
* {@inheritdoc}
96+
* @inheritdoc
9397
*/
9498
public static function getVersion()
9599
{
96100
return '2.0.0';
97101
}
98102

99103
/**
100-
* {@inheritdoc}
104+
* @inheritdoc
101105
*/
102106
public function getAliases()
103107
{

0 commit comments

Comments
 (0)