InitializeMsrpAttributes.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Msrp\Setup\Patch\Data;
  7. use Magento\Eav\Setup\EavSetup;
  8. use Magento\Eav\Setup\EavSetupFactory;
  9. use Magento\Framework\Setup\InstallDataInterface;
  10. use Magento\Framework\Setup\ModuleContextInterface;
  11. use Magento\Framework\Setup\ModuleDataSetupInterface;
  12. use Magento\Framework\App\ResourceConnection;
  13. use Magento\Framework\Setup\Patch\DataPatchInterface;
  14. use Magento\Framework\Setup\Patch\PatchVersionInterface;
  15. class InitializeMsrpAttributes implements DataPatchInterface, PatchVersionInterface
  16. {
  17. /**
  18. * @var \Magento\Framework\Setup\ModuleDataSetupInterface
  19. */
  20. private $moduleDataSetup;
  21. /**
  22. * @var EavSetupFactory
  23. */
  24. private $eavSetupFactory;
  25. /**
  26. * PatchInitial constructor.
  27. * @param \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup
  28. */
  29. public function __construct(
  30. \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup,
  31. EavSetupFactory $eavSetupFactory
  32. ) {
  33. $this->moduleDataSetup = $moduleDataSetup;
  34. $this->eavSetupFactory = $eavSetupFactory;
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function apply()
  40. {
  41. /** @var EavSetup $eavSetup */
  42. $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
  43. $productTypes = [
  44. \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE,
  45. \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL,
  46. \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE,
  47. \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE,
  48. ];
  49. $productTypes = join(',', $productTypes);
  50. $eavSetup->addAttribute(
  51. \Magento\Catalog\Model\Product::ENTITY,
  52. 'msrp',
  53. [
  54. 'group' => 'Advanced Pricing',
  55. 'backend' => \Magento\Catalog\Model\Product\Attribute\Backend\Price::class,
  56. 'frontend' => '',
  57. 'label' => 'Manufacturer\'s Suggested Retail Price',
  58. 'type' => 'decimal',
  59. 'input' => 'price',
  60. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE,
  61. 'visible' => true,
  62. 'required' => false,
  63. 'user_defined' => false,
  64. 'apply_to' => $productTypes,
  65. 'input_renderer' => \Magento\Msrp\Block\Adminhtml\Product\Helper\Form\Type::class,
  66. 'frontend_input_renderer' => \Magento\Msrp\Block\Adminhtml\Product\Helper\Form\Type::class,
  67. 'visible_on_front' => false,
  68. 'used_in_product_listing' => true,
  69. 'is_used_in_grid' => true,
  70. 'is_visible_in_grid' => false,
  71. 'is_filterable_in_grid' => true,
  72. ]
  73. );
  74. $eavSetup->addAttribute(
  75. \Magento\Catalog\Model\Product::ENTITY,
  76. 'msrp_display_actual_price_type',
  77. [
  78. 'group' => 'Advanced Pricing',
  79. 'backend' => \Magento\Catalog\Model\Product\Attribute\Backend\Boolean::class,
  80. 'frontend' => '',
  81. 'label' => 'Display Actual Price',
  82. 'input' => 'select',
  83. 'source' => \Magento\Msrp\Model\Product\Attribute\Source\Type\Price::class,
  84. 'source_model' => \Magento\Msrp\Model\Product\Attribute\Source\Type\Price::class,
  85. 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE,
  86. 'visible' => true,
  87. 'required' => false,
  88. 'user_defined' => false,
  89. 'default' => \Magento\Msrp\Model\Product\Attribute\Source\Type\Price::TYPE_USE_CONFIG,
  90. 'default_value' => \Magento\Msrp\Model\Product\Attribute\Source\Type\Price::TYPE_USE_CONFIG,
  91. 'apply_to' => $productTypes,
  92. 'input_renderer' => \Magento\Msrp\Block\Adminhtml\Product\Helper\Form\Type\Price::class,
  93. 'frontend_input_renderer' => \Magento\Msrp\Block\Adminhtml\Product\Helper\Form\Type\Price::class,
  94. 'visible_on_front' => false,
  95. 'used_in_product_listing' => true
  96. ]
  97. );
  98. }
  99. /**
  100. * {@inheritdoc}
  101. */
  102. public static function getDependencies()
  103. {
  104. return [];
  105. }
  106. /**
  107. * {@inheritdoc}
  108. */
  109. public static function getVersion()
  110. {
  111. return '2.0.0';
  112. }
  113. /**
  114. * {@inheritdoc}
  115. */
  116. public function getAliases()
  117. {
  118. return [];
  119. }
  120. }