Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AddSwatchImageToDefaultAttribtueSet.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Eav\Setup\EavSetupFactory;
14 
20 {
24  private $moduleDataSetup;
25 
29  private $eavSetupFactory;
30 
35  public function __construct(
36  \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup,
37  EavSetupFactory $eavSetupFactory
38  ) {
39  $this->moduleDataSetup = $moduleDataSetup;
40  $this->eavSetupFactory = $eavSetupFactory;
41  }
42 
46  public function apply()
47  {
48  $this->moduleDataSetup->getConnection()->startSetup();
49 
51  $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
52  $attributeSetId = $eavSetup->getDefaultAttributeSetId(Product::ENTITY);
53  $groupId = (int)$eavSetup->getAttributeGroupByCode(
56  'image-management',
57  'attribute_group_id'
58  );
59  $eavSetup->addAttributeToGroup(Product::ENTITY, $attributeSetId, $groupId, 'swatch_image');
60 
61  $this->moduleDataSetup->getConnection()->endSetup();
62  }
63 
67  public static function getDependencies()
68  {
69  return [
70  AddSwatchImageAttribute::class
71  ];
72  }
73 
77  public static function getVersion()
78  {
79  return '2.0.1';
80  }
81 
85  public function getAliases()
86  {
87  return [];
88  }
89 }
__construct(\Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup, EavSetupFactory $eavSetupFactory)