15
15
use Magento \ConfigurableProduct \Model \Product \Type \Configurable ;
16
16
17
17
/**
18
- * Class UpdateManufacturerAttribute
19
- * @package Magento\ConfigurableProduct\Setup\Patch
18
+ * Update manufacturer attribute if it's presented in system.
20
19
*/
21
20
class UpdateManufacturerAttribute implements DataPatchInterface, PatchVersionInterface
22
21
{
@@ -31,7 +30,6 @@ class UpdateManufacturerAttribute implements DataPatchInterface, PatchVersionInt
31
30
private $ eavSetupFactory ;
32
31
33
32
/**
34
- * UpdateTierPriceAttribute constructor.
35
33
* @param ModuleDataSetupInterface $moduleDataSetup
36
34
* @param EavSetupFactory $eavSetupFactory
37
35
*/
@@ -44,30 +42,37 @@ public function __construct(
44
42
}
45
43
46
44
/**
47
- * { @inheritdoc}
45
+ * @inheritdoc
48
46
*/
49
47
public function apply ()
50
48
{
51
49
/** @var EavSetup $eavSetup */
52
50
$ eavSetup = $ this ->eavSetupFactory ->create (['setup ' => $ this ->moduleDataSetup ]);
53
- $ relatedProductTypes = explode (
54
- ', ' ,
55
- $ eavSetup ->getAttribute (\Magento \Catalog \Model \Product::ENTITY , 'manufacturer ' , 'apply_to ' )
56
- );
57
51
58
- if (!in_array (Configurable::TYPE_CODE , $ relatedProductTypes )) {
59
- $ relatedProductTypes [] = Configurable::TYPE_CODE ;
60
- $ eavSetup ->updateAttribute (
61
- \Magento \Catalog \Model \Product::ENTITY ,
62
- 'manufacturer ' ,
63
- 'apply_to ' ,
64
- implode (', ' , $ relatedProductTypes )
52
+ if ($ manufacturer = $ eavSetup ->getAttribute (
53
+ \Magento \Catalog \Model \Product::ENTITY ,
54
+ 'manufacturer ' ,
55
+ 'apply_to '
56
+ )) {
57
+ $ relatedProductTypes = explode (
58
+ ', ' ,
59
+ $ manufacturer
65
60
);
61
+
62
+ if (!in_array (Configurable::TYPE_CODE , $ relatedProductTypes )) {
63
+ $ relatedProductTypes [] = Configurable::TYPE_CODE ;
64
+ $ eavSetup ->updateAttribute (
65
+ \Magento \Catalog \Model \Product::ENTITY ,
66
+ 'manufacturer ' ,
67
+ 'apply_to ' ,
68
+ implode (', ' , $ relatedProductTypes )
69
+ );
70
+ }
66
71
}
67
72
}
68
73
69
74
/**
70
- * { @inheritdoc}
75
+ * @inheritdoc
71
76
*/
72
77
public static function getDependencies ()
73
78
{
@@ -77,15 +82,15 @@ public static function getDependencies()
77
82
}
78
83
79
84
/**
80
- * { @inheritdoc}\
85
+ * @inheritdoc
81
86
*/
82
87
public static function getVersion ()
83
88
{
84
89
return '2.2.1 ' ;
85
90
}
86
91
87
92
/**
88
- * { @inheritdoc}
93
+ * @inheritdoc
89
94
*/
90
95
public function getAliases ()
91
96
{
0 commit comments