6
6
7
7
namespace Magento \ConfigurableProduct \Setup \Patch \Data ;
8
8
9
+ use Magento \ConfigurableProduct \Model \Product \Type \Configurable ;
9
10
use Magento \Eav \Setup \EavSetup ;
10
11
use Magento \Eav \Setup \EavSetupFactory ;
11
- use Magento \Framework \App \ResourceConnection ;
12
12
use Magento \Framework \Setup \ModuleDataSetupInterface ;
13
13
use Magento \Framework \Setup \Patch \DataPatchInterface ;
14
14
use Magento \Framework \Setup \Patch \PatchVersionInterface ;
15
- use Magento \ConfigurableProduct \Model \Product \Type \Configurable ;
16
15
17
16
/**
18
17
* Class InstallInitialConfigurableAttributes
18
+ *
19
19
* @package Magento\ConfigurableProduct\Setup\Patch
20
20
*/
21
21
class InstallInitialConfigurableAttributes implements DataPatchInterface, PatchVersionInterface
@@ -24,6 +24,7 @@ class InstallInitialConfigurableAttributes implements DataPatchInterface, PatchV
24
24
* @var ModuleDataSetupInterface
25
25
*/
26
26
private $ moduleDataSetup ;
27
+
27
28
/**
28
29
* @var EavSetupFactory
29
30
*/
@@ -43,7 +44,7 @@ public function __construct(
43
44
}
44
45
45
46
/**
46
- * { @inheritdoc}
47
+ * @inheritdoc
47
48
*/
48
49
public function apply ()
49
50
{
@@ -64,40 +65,43 @@ public function apply()
64
65
'color '
65
66
];
66
67
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
78
73
);
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
+ }
79
83
}
80
84
}
81
85
}
82
86
83
87
/**
84
- * { @inheritdoc}
88
+ * @inheritdoc
85
89
*/
86
90
public static function getDependencies ()
87
91
{
88
92
return [];
89
93
}
90
94
91
95
/**
92
- * { @inheritdoc}
96
+ * @inheritdoc
93
97
*/
94
98
public static function getVersion ()
95
99
{
96
100
return '2.0.0 ' ;
97
101
}
98
102
99
103
/**
100
- * { @inheritdoc}
104
+ * @inheritdoc
101
105
*/
102
106
public function getAliases ()
103
107
{
0 commit comments