Skip to content

Commit c608d77

Browse files
authored
ENGCOM-3603: Fixed upgrade issue if manufacturer attribute not exist in the database #19514
2 parents 82075e5 + d34ae49 commit c608d77

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1616

1717
/**
18-
* Class UpdateManufacturerAttribute
19-
* @package Magento\ConfigurableProduct\Setup\Patch
18+
* Update manufacturer attribute if it's presented in system.
2019
*/
2120
class UpdateManufacturerAttribute implements DataPatchInterface, PatchVersionInterface
2221
{
@@ -31,7 +30,6 @@ class UpdateManufacturerAttribute implements DataPatchInterface, PatchVersionInt
3130
private $eavSetupFactory;
3231

3332
/**
34-
* UpdateTierPriceAttribute constructor.
3533
* @param ModuleDataSetupInterface $moduleDataSetup
3634
* @param EavSetupFactory $eavSetupFactory
3735
*/
@@ -44,30 +42,37 @@ public function __construct(
4442
}
4543

4644
/**
47-
* {@inheritdoc}
45+
* @inheritdoc
4846
*/
4947
public function apply()
5048
{
5149
/** @var EavSetup $eavSetup */
5250
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
53-
$relatedProductTypes = explode(
54-
',',
55-
$eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'manufacturer', 'apply_to')
56-
);
5751

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
6560
);
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+
}
6671
}
6772
}
6873

6974
/**
70-
* {@inheritdoc}
75+
* @inheritdoc
7176
*/
7277
public static function getDependencies()
7378
{
@@ -77,15 +82,15 @@ public static function getDependencies()
7782
}
7883

7984
/**
80-
* {@inheritdoc}\
85+
* @inheritdoc
8186
*/
8287
public static function getVersion()
8388
{
8489
return '2.2.1';
8590
}
8691

8792
/**
88-
* {@inheritdoc}
93+
* @inheritdoc
8994
*/
9095
public function getAliases()
9196
{

0 commit comments

Comments
 (0)