Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. <?php
  2. declare(strict_types=1);
  3.  
  4. namespace Anshu\Catalog\Setup\Patch\Data;
  5.  
  6. use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
  7. use Magento\Eav\Setup\EavSetup;
  8. use Magento\Eav\Setup\EavSetupFactory;
  9. use Magento\Framework\Setup\ModuleDataSetupInterface;
  10. use Magento\Framework\Setup\Patch\DataPatchInterface;
  11.  
  12. class AddRecommendedAttribute implements DataPatchInterface
  13. {
  14. /**
  15. * ModuleDataSetupInterface
  16. *
  17. * @var ModuleDataSetupInterface
  18. */
  19. private $moduleDataSetup;
  20.  
  21. /**
  22. * EavSetupFactory
  23. *
  24. * @var EavSetupFactory
  25. */
  26. private $eavSetupFactory;
  27.  
  28. /**
  29. * AddRecommendedAttribute constructor.
  30. *
  31. * @param ModuleDataSetupInterface $moduleDataSetup
  32. * @param EavSetupFactory $eavSetupFactory
  33. */
  34. public function __construct(
  35. ModuleDataSetupInterface $moduleDataSetup,
  36. EavSetupFactory $eavSetupFactory
  37. ) {
  38. $this->moduleDataSetup = $moduleDataSetup;
  39. $this->eavSetupFactory = $eavSetupFactory;
  40. }
  41.  
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function apply()
  46. {
  47. /** @var EavSetup $eavSetup */
  48. $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
  49.  
  50. $eavSetup->addAttribute('catalog_product', 'recommended', [
  51. 'type' => 'int',
  52. 'label' => 'Is Recommended',
  53. 'input' => 'select',
  54. 'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
  55. 'default' => 0,
  56. 'global' => ScopedAttributeInterface::SCOPE_STORE,
  57. 'visible' => true,
  58. 'used_in_product_listing' => true,
  59. 'user_defined' => true,
  60. 'required' => false,
  61. 'group' => 'General',
  62. 'sort_order' => 80,
  63. ]);
  64. }
  65.  
  66. /**
  67. * {@inheritdoc}
  68. */
  69. public static function getDependencies()
  70. {
  71. return [];
  72. }
  73.  
  74. /**
  75. * {@inheritdoc}
  76. */
  77. public function getAliases()
  78. {
  79. return [];
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement