AddSwatchImageAttribute.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\Catalog\Model\Product\Attribute\Frontend\Image;
  8. use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
  9. use Magento\Eav\Setup\EavSetupFactory;
  10. use Magento\Eav\Setup\EavSetup;
  11. use Magento\Framework\App\ResourceConnection;
  12. use Magento\Framework\Setup\Patch\DataPatchInterface;
  13. use Magento\Framework\Setup\Patch\PatchVersionInterface;
  14. /**
  15. * Class AddSwatchImageAttribute
  16. * @package Magento\Swatches\Setup\Patch
  17. */
  18. class AddSwatchImageAttribute implements DataPatchInterface, PatchVersionInterface
  19. {
  20. /**
  21. * @var \Magento\Framework\Setup\ModuleDataSetupInterface
  22. */
  23. private $moduleDataSetup;
  24. /**
  25. * @var EavSetupFactory
  26. */
  27. private $eavSetupFactory;
  28. /**
  29. * AddSwatchImageAttribute constructor.
  30. * @param \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup
  31. * @param EavSetupFactory $eavSetupFactory
  32. */
  33. public function __construct(
  34. \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup,
  35. EavSetupFactory $eavSetupFactory
  36. ) {
  37. $this->moduleDataSetup = $moduleDataSetup;
  38. $this->eavSetupFactory = $eavSetupFactory;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function apply()
  44. {
  45. /** @var EavSetup $eavSetup */
  46. $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
  47. /**
  48. * Install eav entity types to the eav/entity_type table
  49. */
  50. $eavSetup->addAttribute(
  51. 'catalog_product',
  52. 'swatch_image',
  53. [
  54. 'type' => 'varchar',
  55. 'label' => 'Swatch',
  56. 'input' => 'media_image',
  57. 'frontend' => Image::class,
  58. 'required' => false,
  59. 'sort_order' => 3,
  60. 'global' => ScopedAttributeInterface::SCOPE_STORE,
  61. 'used_in_product_listing' => true
  62. ]
  63. );
  64. }
  65. /**
  66. * {@inheritdoc}
  67. */
  68. public static function getDependencies()
  69. {
  70. return [];
  71. }
  72. /**
  73. * {@inheritdoc}
  74. */
  75. public static function getVersion()
  76. {
  77. return '2.0.0';
  78. }
  79. /**
  80. * {@inheritdoc}
  81. */
  82. public function getAliases()
  83. {
  84. return [];
  85. }
  86. }