Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InstallInitialConfigurableAttributes.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Eav\Setup\EavSetupFactory;
16 
22 {
26  private $moduleDataSetup;
30  private $eavSetupFactory;
31 
37  public function __construct(
38  ModuleDataSetupInterface $moduleDataSetup,
39  EavSetupFactory $eavSetupFactory
40  ) {
41  $this->moduleDataSetup = $moduleDataSetup;
42  $this->eavSetupFactory = $eavSetupFactory;
43  }
44 
48  public function apply()
49  {
51  $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
52  $attributes = [
53  'country_of_manufacture',
54  'manufacturer',
55  'minimal_price',
56  'msrp',
57  'msrp_display_actual_price_type',
58  'price',
59  'special_price',
60  'special_from_date',
61  'special_to_date',
62  'tier_price',
63  'weight',
64  'color'
65  ];
66  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,
76  'apply_to',
77  implode(',', $relatedProductTypes)
78  );
79  }
80  }
81  }
82 
86  public static function getDependencies()
87  {
88  return [];
89  }
90 
94  public static function getVersion()
95  {
96  return '2.0.0';
97  }
98 
102  public function getAliases()
103  {
104  return [];
105  }
106 }
$attributeCode
Definition: extend.phtml:12
$attributes
Definition: matrix.phtml:13
__construct(ModuleDataSetupInterface $moduleDataSetup, EavSetupFactory $eavSetupFactory)