Useful direct SQL queries for Magento 2 developers
Select product default Attribute set id
1 2 |
//Entity type id = 4 -> The product entity SELECT attribute_set_id FROM `eav_attribute_set` WHERE entity_type_id = 4 and attribute_set_name = 'Default' |
Select product Attribute Group Id by using attribute_group_code and Attribute Set ID
1 |
SELECT attribute_group_id FROM `eav_attribute_group` WHERE attribute_group_code = 'iyngaran' AND attribute_set_id = '4' |
Update attribute_group_id for product attribute
1 2 3 4 |
//attribute_set_id = '4' // the default attribute set //attribute_code = 'iyngaran_pro_val' //attribute_group_code = 'iyngaran' UPDATE `eav_entity_attribute` SET `attribute_group_id` = (SELECT attribute_group_id FROM `eav_attribute_group` WHERE attribute_group_code = 'iyngaran' AND attribute_set_id = '4') WHERE `eav_entity_attribute`.`attribute_id` = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'iyngaran_pro_val'); |
Update sort_order for product attribute
1 2 3 4 |
//sort_order = 2 //attribute_code = 'iyngaran_pro_val' //attribute_group_code = 'iyngaran' UPDATE `eav_entity_attribute` SET `sort_order` = 2 WHERE `attribute_id` = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'iyngaran_pro_val') AND `attribute_group_id` = (SELECT attribute_group_id FROM `eav_attribute_group` WHERE attribute_group_code = 'iyngaran' AND attribute_set_id = '4'); |
Delete a custom attribute using entity_type_id and attribute_code. Delete a custom attribute using entity_type_id and attribute_code. For this example, I am going to delete a product attribute, which has attribute_code as ‘iyn_product_option’. To delete a custom attribute, we need to […]