There are certain bulk actions you can do from “Catalog > Manage Products” section, however they all fail on large number of products selected. Logical solution is to simply use the raw SQL query. Only one catch, knowing where to look for.
Below is a practical example on “How to bulk update product status based on product category”. In my case, the id of my category in question was 35, while my “status” attribute had an id of 80. Most likely yours “status” attribute will have the same id value given that its a default Magento attribute.
Here is the actual SQL code that disables the products which have only one category assigned, the one with id 35:
UPDATE ma_catalog_product_entity_int SET value = '2' WHERE attribute_id = 80 AND entity_id IN (SELECT entity_id FROM ma_catalog_product_entity WHERE category_ids = '35');
Code above executed under two seconds, disabling around 6500 products in one run. Doing something like this purely from PHP or shall I say Magento can turn out to be “mission impossible”.
Only one advice, always do a full database backup prior to any database changes.
This works but Magento's status field is not always mapped to attribute_id 80. It's mapped to 84 on mine. You can find what yours is by going to the manage attributes page on your magento install and hovering over the status attribute. Look for the two digit number directly after blahblahblah/attribute_id/**/
ReplyDeletePretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. Best Magento 2 Hosting
ReplyDelete