Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MoveGiftMessageToGiftOptionsGroup.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Catalog\Setup\CategorySetupFactory;
17 
19 {
23  private $moduleDataSetup;
24 
28  private $categorySetupFactory;
29 
35  public function __construct(
36  \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup,
37  CategorySetupFactory $categorySetupFactory
38  ) {
39  $this->moduleDataSetup = $moduleDataSetup;
40  $this->categorySetupFactory = $categorySetupFactory;
41  }
42 
46  public function apply()
47  {
48  $this->moduleDataSetup->getConnection()->startSetup();
49 
51  $categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
52  $entityTypeId = $categorySetup->getEntityTypeId(Product::ENTITY);
53  $attributeSetId = $categorySetup->getDefaultAttributeSetId(Product::ENTITY);
54  $attribute = $categorySetup->getAttribute($entityTypeId, 'gift_message_available');
55 
56  $groupName = 'Gift Options';
57 
58  if (!$categorySetup->getAttributeGroup(Product::ENTITY, $attributeSetId, $groupName)) {
59  $categorySetup->addAttributeGroup(Product::ENTITY, $attributeSetId, $groupName, 60);
60  }
61  $categorySetup->addAttributeToGroup(
64  $groupName,
65  $attribute['attribute_id'],
66  10
67  );
68  $this->moduleDataSetup->getConnection()->endSetup();
69  }
70 
74  public static function getDependencies()
75  {
76  return [
77  AddGiftMessageAttributes::class,
78  ];
79  }
80 
84  public static function getVersion()
85  {
86  return '2.0.1';
87  }
88 
92  public function getAliases()
93  {
94  return [];
95  }
96 }
__construct(\Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup, CategorySetupFactory $categorySetupFactory)