MoveGiftMessageToGiftOptionsGroup.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\GiftMessage\Setup\Patch\Data;
  7. use Magento\Catalog\Model\Product;
  8. use Magento\Catalog\Setup\CategorySetupFactory;
  9. use Magento\Framework\Setup\ModuleContextInterface;
  10. use Magento\Framework\Setup\ModuleDataSetupInterface;
  11. use Magento\Framework\Setup\UpgradeDataInterface;
  12. use Magento\Framework\App\ResourceConnection;
  13. use Magento\Framework\Setup\Patch\DataPatchInterface;
  14. use Magento\Framework\Setup\Patch\PatchVersionInterface;
  15. class MoveGiftMessageToGiftOptionsGroup implements DataPatchInterface, PatchVersionInterface
  16. {
  17. /**
  18. * @var \Magento\Framework\Setup\ModuleDataSetupInterface
  19. */
  20. private $moduleDataSetup;
  21. /**
  22. * @var CategorySetupFactory
  23. */
  24. private $categorySetupFactory;
  25. /**
  26. * MoveGiftMessageToGiftOptionsGroup constructor.
  27. * @param \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup
  28. * @param CategorySetupFactory $categorySetupFactory
  29. */
  30. public function __construct(
  31. \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup,
  32. CategorySetupFactory $categorySetupFactory
  33. ) {
  34. $this->moduleDataSetup = $moduleDataSetup;
  35. $this->categorySetupFactory = $categorySetupFactory;
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function apply()
  41. {
  42. $this->moduleDataSetup->getConnection()->startSetup();
  43. /** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */
  44. $categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
  45. $entityTypeId = $categorySetup->getEntityTypeId(Product::ENTITY);
  46. $attributeSetId = $categorySetup->getDefaultAttributeSetId(Product::ENTITY);
  47. $attribute = $categorySetup->getAttribute($entityTypeId, 'gift_message_available');
  48. $groupName = 'Gift Options';
  49. if (!$categorySetup->getAttributeGroup(Product::ENTITY, $attributeSetId, $groupName)) {
  50. $categorySetup->addAttributeGroup(Product::ENTITY, $attributeSetId, $groupName, 60);
  51. }
  52. $categorySetup->addAttributeToGroup(
  53. $entityTypeId,
  54. $attributeSetId,
  55. $groupName,
  56. $attribute['attribute_id'],
  57. 10
  58. );
  59. $this->moduleDataSetup->getConnection()->endSetup();
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public static function getDependencies()
  65. {
  66. return [
  67. AddGiftMessageAttributes::class,
  68. ];
  69. }
  70. /**
  71. * {@inheritdoc}
  72. */
  73. public static function getVersion()
  74. {
  75. return '2.0.1';
  76. }
  77. /**
  78. * {@inheritdoc}
  79. */
  80. public function getAliases()
  81. {
  82. return [];
  83. }
  84. }