Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InitializeGroupedProductLinks.php
Go to the documentation of this file.
1 <?php
8 
11 use Magento\Eav\Setup\EavSetupFactory;
15 
21 {
25  private $moduleDataSetup;
26 
30  private $eavSetupFactory;
31 
37  public function __construct(
38  \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup,
39  EavSetupFactory $eavSetupFactory
40  ) {
41  $this->moduleDataSetup = $moduleDataSetup;
42  $this->eavSetupFactory = $eavSetupFactory;
43  }
44 
48  public function apply()
49  {
53  $data = [
55  'code' => 'super',
56  ];
57  $this->moduleDataSetup->getConnection()->insertOnDuplicate(
58  $this->moduleDataSetup->getTable('catalog_product_link_type'),
59  $data
60  );
61 
65  $select = $this->moduleDataSetup->getConnection()
66  ->select()
67  ->from(
68  ['c' => $this->moduleDataSetup->getTable('catalog_product_link_attribute')]
69  )
70  ->where(
71  "c.link_type_id=?",
72  \Magento\GroupedProduct\Model\ResourceModel\Product\Link::LINK_TYPE_GROUPED
73  );
74  $result = $this->moduleDataSetup->getConnection()->fetchAll($select);
75  if (!$result) {
76  $data = [
77  [
79  'product_link_attribute_code' => 'position',
80  'data_type' => 'int',
81  ],
82  [
84  'product_link_attribute_code' => 'qty',
85  'data_type' => 'decimal'
86  ],
87  ];
88  $this->moduleDataSetup->getConnection()->insertMultiple(
89  $this->moduleDataSetup->getTable('catalog_product_link_attribute'),
90  $data
91  );
92  }
94  $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
95  $field = 'country_of_manufacture';
96  $applyTo = explode(',', $eavSetup->getAttribute(Product::ENTITY, $field, 'apply_to'));
97  if (!in_array('grouped', $applyTo)) {
98  $applyTo[] = 'grouped';
99  $eavSetup->updateAttribute(Product::ENTITY, $field, 'apply_to', implode(',', $applyTo));
100  }
101  }
102 
106  public static function getDependencies()
107  {
108  return [];
109  }
110 
114  public static function getVersion()
115  {
116  return '2.0.0';
117  }
118 
122  public function getAliases()
123  {
124  return [];
125  }
126 }