UpdateGiftMessageAttribute.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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\App\ResourceConnection;
  10. use Magento\Framework\Setup\Patch\DataPatchInterface;
  11. use Magento\Framework\Setup\Patch\PatchVersionInterface;
  12. /**
  13. * Class UpdateGiftMessageAttribute
  14. * @package Magento\GiftMessage\Setup\Patch
  15. */
  16. class UpdateGiftMessageAttribute implements DataPatchInterface, PatchVersionInterface
  17. {
  18. /**
  19. * @var \Magento\Framework\Setup\ModuleDataSetupInterface
  20. */
  21. private $moduleDataSetup;
  22. /**
  23. * @var CategorySetupFactory
  24. */
  25. private $categorySetupFactory;
  26. /**
  27. * UpdateGiftMessageAttribute constructor.
  28. * @param \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup
  29. * @param CategorySetupFactory $categorySetupFactory
  30. */
  31. public function __construct(
  32. \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup,
  33. CategorySetupFactory $categorySetupFactory
  34. ) {
  35. $this->moduleDataSetup = $moduleDataSetup;
  36. $this->categorySetupFactory = $categorySetupFactory;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function apply()
  42. {
  43. $this->moduleDataSetup->getConnection()->startSetup();
  44. /** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */
  45. $categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
  46. $entityTypeId = $categorySetup->getEntityTypeId(Product::ENTITY);
  47. $attribute = $categorySetup->getAttribute($entityTypeId, 'gift_message_available');
  48. $categorySetup->updateAttribute(
  49. $entityTypeId,
  50. $attribute['attribute_id'],
  51. 'source_model',
  52. \Magento\Catalog\Model\Product\Attribute\Source\Boolean::class
  53. );
  54. $this->moduleDataSetup->getConnection()->endSetup();
  55. }
  56. /**
  57. * {@inheritdoc}
  58. */
  59. public static function getDependencies()
  60. {
  61. return [
  62. MoveGiftMessageToGiftOptionsGroup::class
  63. ];
  64. }
  65. /**
  66. * {@inheritdoc}
  67. */
  68. public static function getVersion()
  69. {
  70. return '2.1.0';
  71. }
  72. /**
  73. * {@inheritdoc}
  74. */
  75. public function getAliases()
  76. {
  77. return [];
  78. }
  79. }