Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AddSwatchImageAttribute.php
Go to the documentation of this file.
1 <?php
8 
11 use Magento\Eav\Setup\EavSetupFactory;
16 
22 {
26  private $moduleDataSetup;
27 
31  private $eavSetupFactory;
32 
38  public function __construct(
39  \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup,
40  EavSetupFactory $eavSetupFactory
41  ) {
42  $this->moduleDataSetup = $moduleDataSetup;
43  $this->eavSetupFactory = $eavSetupFactory;
44  }
45 
49  public function apply()
50  {
52  $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
53 
57  $eavSetup->addAttribute(
58  'catalog_product',
59  'swatch_image',
60  [
61  'type' => 'varchar',
62  'label' => 'Swatch',
63  'input' => 'media_image',
64  'frontend' => Image::class,
65  'required' => false,
66  'sort_order' => 3,
68  'used_in_product_listing' => true
69  ]
70  );
71  }
72 
76  public static function getDependencies()
77  {
78  return [];
79  }
80 
84  public static function getVersion()
85  {
86  return '2.0.0';
87  }
88 
92  public function getAliases()
93  {
94  return [];
95  }
96 }
__construct(\Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup, EavSetupFactory $eavSetupFactory)