Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InitializeMsrpAttributes.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Eav\Setup\EavSetupFactory;
17 
19 {
23  private $moduleDataSetup;
24 
28  private $eavSetupFactory;
29 
34  public function __construct(
35  \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup,
36  EavSetupFactory $eavSetupFactory
37  ) {
38  $this->moduleDataSetup = $moduleDataSetup;
39  $this->eavSetupFactory = $eavSetupFactory;
40  }
41 
45  public function apply()
46  {
48  $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
49 
50  $productTypes = [
51  \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE,
52  \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL,
54  \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE,
55  ];
56  $productTypes = join(',', $productTypes);
57  $eavSetup->addAttribute(
58  \Magento\Catalog\Model\Product::ENTITY,
59  'msrp',
60  [
61  'group' => 'Advanced Pricing',
62  'backend' => \Magento\Catalog\Model\Product\Attribute\Backend\Price::class,
63  'frontend' => '',
64  'label' => 'Manufacturer\'s Suggested Retail Price',
65  'type' => 'decimal',
66  'input' => 'price',
67  'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE,
68  'visible' => true,
69  'required' => false,
70  'user_defined' => false,
71  'apply_to' => $productTypes,
72  'input_renderer' => \Magento\Msrp\Block\Adminhtml\Product\Helper\Form\Type::class,
73  'frontend_input_renderer' => \Magento\Msrp\Block\Adminhtml\Product\Helper\Form\Type::class,
74  'visible_on_front' => false,
75  'used_in_product_listing' => true,
76  'is_used_in_grid' => true,
77  'is_visible_in_grid' => false,
78  'is_filterable_in_grid' => true,
79  ]
80  );
81  $eavSetup->addAttribute(
82  \Magento\Catalog\Model\Product::ENTITY,
83  'msrp_display_actual_price_type',
84  [
85  'group' => 'Advanced Pricing',
86  'backend' => \Magento\Catalog\Model\Product\Attribute\Backend\Boolean::class,
87  'frontend' => '',
88  'label' => 'Display Actual Price',
89  'input' => 'select',
90  'source' => \Magento\Msrp\Model\Product\Attribute\Source\Type\Price::class,
91  'source_model' => \Magento\Msrp\Model\Product\Attribute\Source\Type\Price::class,
92  'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE,
93  'visible' => true,
94  'required' => false,
95  'user_defined' => false,
96  'default' => \Magento\Msrp\Model\Product\Attribute\Source\Type\Price::TYPE_USE_CONFIG,
97  'default_value' => \Magento\Msrp\Model\Product\Attribute\Source\Type\Price::TYPE_USE_CONFIG,
98  'apply_to' => $productTypes,
99  'input_renderer' => \Magento\Msrp\Block\Adminhtml\Product\Helper\Form\Type\Price::class,
100  'frontend_input_renderer' => \Magento\Msrp\Block\Adminhtml\Product\Helper\Form\Type\Price::class,
101  'visible_on_front' => false,
102  'used_in_product_listing' => true
103  ]
104  );
105  }
106 
110  public static function getDependencies()
111  {
112  return [];
113  }
114 
118  public static function getVersion()
119  {
120  return '2.0.0';
121  }
122 
126  public function getAliases()
127  {
128  return [];
129  }
130 }
__construct(\Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup, EavSetupFactory $eavSetupFactory)