![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/extmag/shiplab/Setup/Patch/Data/ |
<?php /** * Copyright © Extmag. All rights reserved. */ namespace Extmag\Shiplab\Setup\Patch\Data; use Magento\Catalog\Model\Category; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchRevertableInterface; class CreateEAVAttributesCategory implements DataPatchInterface, PatchRevertableInterface { /** * @var EavSetupFactory */ public $eavSetupFactory; /** * @var ModuleDataSetupInterface */ public $moduleDataSetup; /** * @param ModuleDataSetupInterface $moduleDataSetup * @param EavSetupFactory $eavSetupFactory */ public function __construct( ModuleDataSetupInterface $moduleDataSetup, EavSetupFactory $eavSetupFactory ) { $this->moduleDataSetup = $moduleDataSetup; $this->eavSetupFactory = $eavSetupFactory; } /** * {@inheritdoc} */ public static function getDependencies() { return [ /*SomeDependency::class*/ ]; } /** * {@inheritdoc} */ public function apply() { $this->moduleDataSetup->getConnection()->startSetup(); $this->moduleDataSetup->getConnection()->endSetup(); } public function revert() { $this->moduleDataSetup->getConnection()->startSetup(); $this->moduleDataSetup->getConnection()->endSetup(); } /** * {@inheritdoc} */ public function getAliases() { return []; } /** * @param $attributeName * @param $attributeLabel * @param string $type * @param int $sort * @param array $options */ public function setEAVAttribute($attributeName, $attributeLabel, $type = 'text', $sort = 1, $options = []) { $entityTypeId = Category::ENTITY; $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); $attributeSetId = $eavSetup->getDefaultAttributeSetId($entityTypeId); /** * Adding an attribute to a custom group */ $attributeId = $eavSetup->getAttributeId($entityTypeId, $attributeName); $customGroupName = 'Extmag'; $arrOptions = [ 'label' => $attributeLabel, 'user_defined' => 1, 'searchable' => 1, 'required' => 0, 'visible_on_front' => 0, 'visible_in_advanced_search' => 0, 'group' => $customGroupName, 'input' => $type, 'sort_order' => $sort, ]; if ($type == 'select' || $type == 'multiselect') { $arrOptions['option'] = ['values' => $options]; } $eavSetup->addAttribute( $entityTypeId, $attributeName, $arrOptions ); $eavSetup->addAttributeGroup($entityTypeId, $attributeSetId, $customGroupName, 10); $eavSetup->addAttributeToGroup($entityTypeId, $attributeSetId, $customGroupName, $attributeId); } }