Advertisement
Guest User

Untitled

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