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.
Anyone know how can I do this?I found something which may help.
-
share the code which you used to create attribute?Dhiren Vasoya– Dhiren Vasoya2018年08月24日 14:17:06 +00:00Commented Aug 24, 2018 at 14:17
-
i have show in link,but i want also when admin create from backendKetan Borada– Ketan Borada2018年08月25日 05:41:18 +00:00Commented Aug 25, 2018 at 5:41
2 Answers 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'
]
);
-
Yes,but it not solved my problem I want to remove all child-product's attributes from bundle/configurable category page in layered navigation filterKetan Borada– Ketan Borada2018年08月25日 10:19:14 +00:00Commented Aug 25, 2018 at 10:19
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.
-
Yes,but it not solved my problem I want to remove all child-product's attributes from bundle/configurable category page in layered navigation filterKetan Borada– Ketan Borada2018年08月25日 10:19:18 +00:00Commented Aug 25, 2018 at 10:19
Explore related questions
See similar questions with these tags.