Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare(strict_types=1);
- namespace Anshu\Category\Setup\Patch\Data;
- use Magento\Catalog\Model\Category;
- use Magento\Catalog\Setup\CategorySetupFactory;
- use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
- use Magento\Eav\Model\Entity\Attribute\Source\Boolean;
- use Magento\Eav\Setup\EavSetup;
- use Magento\Eav\Setup\EavSetupFactory;
- use Magento\Framework\Setup\ModuleDataSetupInterface;
- use Magento\Framework\Setup\Patch\DataPatchInterface;
- class AddCategoryRecommended implements DataPatchInterface
- {
- /**
- * ModuleDataSetupInterface
- *
- * @var ModuleDataSetupInterface
- */
- private $moduleDataSetup;
- /**
- * EavSetupFactory
- *
- * @var EavSetupFactory
- */
- private $eavSetupFactory;
- /**
- * CategorySetupFactory
- *
- * @var CategorySetupFactory
- */
- private $categorySetupFactory;
- /**
- * AddCategoryRecommended constructor.
- * @param ModuleDataSetupInterface $moduleDataSetup
- * @param EavSetupFactory $eavSetupFactory
- * @param CategorySetupFactory $categorySetupFactory
- */
- public function __construct(
- ModuleDataSetupInterface $moduleDataSetup,
- EavSetupFactory $eavSetupFactory,
- CategorySetupFactory $categorySetupFactory
- ) {
- $this->moduleDataSetup = $moduleDataSetup;
- $this->eavSetupFactory = $eavSetupFactory;
- $this->categorySetupFactory = $categorySetupFactory;
- }
- /**
- * {@inheritdoc}
- */
- public function apply()
- {
- /** @var EavSetup $eavSetup */
- $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
- $eavSetup->addAttribute(Category::ENTITY, 'category_recommendation', [
- 'type' => 'int',
- 'label' => 'Is Recommended',
- 'input' => 'select',
- 'source' => Boolean::class,
- 'sort_order' => 26,
- 'global' => ScopedAttributeInterface::SCOPE_STORE,
- 'group' => 'General Information'
- ]);
- }
- /**
- * {@inheritdoc}
- */
- public static function getDependencies()
- {
- return [];
- }
- /**
- * {@inheritdoc}
- */
- public function getAliases()
- {
- return [];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement