0

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.

2
  • share the code which you used to create attribute? Aug 24, 2018 at 14:17
  • i have show in link,but i want also when admin create from backend Aug 25, 2018 at 5:41

2 Answers 2

2

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'
            ]
        );
1
  • Yes,but it not solved my problem I want to remove all child-product's attributes from bundle/configurable category page in layered navigation filter Aug 25, 2018 at 10:19
1

In Magento 2, there is no option to choose a specific product while creating product attribute.

Easy for your reference: What happened to the "Apply to" feature on product attributes in Magento 2?

You can achieve this in two ways.

By creating attribute via setup script:

If you want to create a custom attribute for a specific product type, we can use the setup script apply_to parameter.

Easy for your reference: Magento2 custom attribute for specific product type

By direct mysql qurey:

If you want to change the admin created custom attribute, we can directly change the apply_to in the database by using the below query.

Note: apply_to default value is NULL.

update catalog_eav_attribute set apply_to="simple" where attribute_id = (select attribute_id from eav_attribute where attribute_code="test");

Hope it helps.

1
  • Yes,but it not solved my problem I want to remove all child-product's attributes from bundle/configurable category page in layered navigation filter Aug 25, 2018 at 10:19

Your Answer

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

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