Skip to content

Commit 99b3899

Browse files
committed
MAGETWO-87047: Manufacturer attribute not appearing in Configurable Products on the backend
1 parent 8c0ac6d commit 99b3899

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

app/code/Magento/ConfigurableProduct/Setup/InstallData.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
4444
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
4545
$attributes = [
4646
'country_of_manufacture',
47+
'manufacturer',
4748
'minimal_price',
4849
'msrp',
4950
'msrp_display_actual_price_type',

app/code/Magento/ConfigurableProduct/Setup/UpgradeData.php

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\ConfigurableProduct\Setup;
77

8+
use Magento\Catalog\Model\Product;
89
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
910
use Magento\Framework\Setup\UpgradeDataInterface;
1011
use Magento\Framework\Setup\ModuleContextInterface;
@@ -41,25 +42,59 @@ public function __construct(EavSetupFactory $eavSetupFactory)
4142
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
4243
{
4344
$setup->startSetup();
45+
/** @var EavSetup $eavSetup */
46+
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
47+
4448
if (version_compare($context->getVersion(), '2.2.0') < 0) {
45-
/** @var EavSetup $eavSetup */
46-
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
47-
$relatedProductTypes = explode(
48-
',',
49-
$eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'tier_price', 'apply_to')
50-
);
49+
$relatedProductTypes = $this->getRelatedProductTypes('tier_price', $eavSetup);
5150
$key = array_search(Configurable::TYPE_CODE, $relatedProductTypes);
5251
if ($key !== false) {
5352
unset($relatedProductTypes[$key]);
54-
$eavSetup->updateAttribute(
55-
\Magento\Catalog\Model\Product::ENTITY,
56-
'tier_price',
57-
'apply_to',
58-
implode(',', $relatedProductTypes)
59-
);
53+
$this->updateRelatedProductTypes('tier_price', $relatedProductTypes, $eavSetup);
54+
}
55+
}
56+
57+
if (version_compare($context->getVersion(), '2.2.1') < 0) {
58+
$relatedProductTypes = $this->getRelatedProductTypes('manufacturer', $eavSetup);
59+
if (!in_array(Configurable::TYPE_CODE, $relatedProductTypes)) {
60+
$relatedProductTypes[] = Configurable::TYPE_CODE;
61+
$this->updateRelatedProductTypes('manufacturer', $relatedProductTypes, $eavSetup);
6062
}
6163
}
6264

6365
$setup->endSetup();
6466
}
67+
68+
/**
69+
* Get related product types for attribute.
70+
*
71+
* @param string $attributeId
72+
* @param EavSetup $eavSetup
73+
* @return array
74+
*/
75+
private function getRelatedProductTypes(string $attributeId, EavSetup $eavSetup)
76+
{
77+
return explode(
78+
',',
79+
$eavSetup->getAttribute(Product::ENTITY, $attributeId, 'apply_to')
80+
);
81+
}
82+
83+
/**
84+
* Update related product types for attribute.
85+
*
86+
* @param string $attributeId
87+
* @param array $relatedProductTypes
88+
* @param EavSetup $eavSetup
89+
* @return void
90+
*/
91+
private function updateRelatedProductTypes(string $attributeId, array $relatedProductTypes, EavSetup $eavSetup)
92+
{
93+
$eavSetup->updateAttribute(
94+
Product::ENTITY,
95+
$attributeId,
96+
'apply_to',
97+
implode(',', $relatedProductTypes)
98+
);
99+
}
65100
}

app/code/Magento/ConfigurableProduct/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_ConfigurableProduct" setup_version="2.2.0">
9+
<module name="Magento_ConfigurableProduct" setup_version="2.2.1">
1010
<sequence>
1111
<module name="Magento_Catalog"/>
1212
<module name="Magento_Msrp"/>

0 commit comments

Comments
 (0)