AddSwatchImageToDefaultAttribtueSet.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Swatches\Setup\Patch\Data;
  7. use Magento\Eav\Setup\EavSetupFactory;
  8. use Magento\Catalog\Model\Product;
  9. use Magento\Framework\App\ResourceConnection;
  10. use Magento\Framework\Setup\Patch\DataPatchInterface;
  11. use Magento\Framework\Setup\Patch\PatchVersionInterface;
  12. /**
  13. * Class AddSwatchImageToDefaultAttribtueSet
  14. * @package Magento\Swatches\Setup\Patch
  15. */
  16. class AddSwatchImageToDefaultAttribtueSet implements DataPatchInterface, PatchVersionInterface
  17. {
  18. /**
  19. * @var \Magento\Framework\Setup\ModuleDataSetupInterface
  20. */
  21. private $moduleDataSetup;
  22. /**
  23. * @var EavSetupFactory
  24. */
  25. private $eavSetupFactory;
  26. /**
  27. * PatchInitial constructor.
  28. * @param \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup
  29. */
  30. public function __construct(
  31. \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup,
  32. EavSetupFactory $eavSetupFactory
  33. ) {
  34. $this->moduleDataSetup = $moduleDataSetup;
  35. $this->eavSetupFactory = $eavSetupFactory;
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function apply()
  41. {
  42. $this->moduleDataSetup->getConnection()->startSetup();
  43. /** @var \Magento\Eav\Setup\EavSetup $eavSetup */
  44. $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
  45. $attributeSetId = $eavSetup->getDefaultAttributeSetId(Product::ENTITY);
  46. $groupId = (int)$eavSetup->getAttributeGroupByCode(
  47. Product::ENTITY,
  48. $attributeSetId,
  49. 'image-management',
  50. 'attribute_group_id'
  51. );
  52. $eavSetup->addAttributeToGroup(Product::ENTITY, $attributeSetId, $groupId, 'swatch_image');
  53. $this->moduleDataSetup->getConnection()->endSetup();
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public static function getDependencies()
  59. {
  60. return [
  61. AddSwatchImageAttribute::class
  62. ];
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public static function getVersion()
  68. {
  69. return '2.0.1';
  70. }
  71. /**
  72. * {@inheritdoc}
  73. */
  74. public function getAliases()
  75. {
  76. return [];
  77. }
  78. }