3

I need to create brand attribute in fabric attribute set.

<?php

namespace XXX\YYY\Setup\Patch\Data;

use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Setup\EavSetupFactory;
use XXX\YYY\Model\Config\Source\Options;

class AddCustomManufacturerAttribute implements DataPatchInterface
{
    const ATTRIBUTE_NAME = 'brand';

    protected $eavSetupFactory;
    private $moduleDataSetup;

    public function __construct(ModuleDataSetupInterface $moduleDataSetup, EavSetupFactory $eavSetupFactory)
    {
        $this->moduleDataSetup = $moduleDataSetup;
        $this->eavSetupFactory = $eavSetupFactory;
    }

    public static function getDependencies()
    {
        return [

        ];
    }

    public function apply()
    {
        $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);       
        $eavSetup->addAttribute(
            \Magento\Catalog\Model\Product::ENTITY, self::ATTRIBUTE_NAME, [
                'type' => 'int',
                'backend' => '',
                'attribute' => '',
                'frontend' => '',
                'label' => 'Brand',
                'input' => 'select',
                'class' => '',
                'source' => Options::class,
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                'visible' => true,
                'required' => true,
                'user_defined' => true,
                'default' => NULL,
                'searchable' => false,
                'filterable' => false,
                'comparable' => false,
                'visible_on_front' => false,
                'used_in_product_listing' => false,
                'used_for_sort_by' => false,
                'unique' => false,
                'apply_to' => 'simple,virtual,downloadable,bundle,configurable',
                'group' => 'Fabric Attributes',
                'is_used_in_grid' => true,
                'is_visible_in_grid' => false,
                'is_filterable_in_grid' => true,
            ]
        );
        $eavSetup->addAttributeToGroup(
            \Magento\Catalog\Model\Product::ENTITY, 'Fabric', 'Fabric Attributes', self::ATTRIBUTE_NAME, 1
        );
    }

    public function getAliases()
    {
        return [];
    }
}

But the brand created in fabric attribute set and also default attribute set.

But,I need to create brand attribute only in fabric attribute set .

If anything i want to change it.

Thanks.

1 Answer 1

0

Just remove this line ..

 'group' => 'Fabric Attributes',
1
  • how can we create multiple attributes at a time?
    – Manjunath
    Commented Mar 19, 2020 at 6:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.