Magento – Adding custom product attribute properties in Magento 2

adminattributesbugmagento2product

How to add custom product attribute properties in admin for admin?

  • Magento2 has removed attribute filter to product type.

  • So,in frontend layer-navigation I'm getting attribute filter of it's child product also for bundle and configurable product in
    category page.

  • I want to add 'Apply To' property when i create new attribute.

  • When I'm creating attribute I want to set scope for product type as we were did in magento1.

enter image description here

Anyone know how can I do this?I found something which may help.

Best Answer

You used attribute code like below. Into code we need to add field

'apply_to'

and into that you need to specify types of product for which you used above attribute. Here I create attribute only for Simple, Group and Bundel type of product.

$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
        $eavSetup->addAttribute(
            \Magento\Catalog\Model\Product::ENTITY,
            'myattribute',
            [
                'type' => 'text',
                'label' => 'My Atrribute',
                'input' => 'text',
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
                'visible' => true,
                'apply_to' => 'simple,grouped,bundle'
            ]
        );
Related Topic