blog site of branko ajzele, senior developer / project manager

Bulk disable multiple Magento products

With all its ORM, model, resource and so on greatness, sometimes platform limitations are too obvious in Magento when it comes to large number of products in store. Recently I faced a simple task, I needed to disable around 6500 products in Magento that were assigned to a single category called “Inactive Products”. Given that it was an import from old system to Magento it is irrelevant why one would use category “Inactive Products” instead of just setting their status to “disabled”. My point is, whats the fastest way to do a bulk action on large number of products.

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.

  • jadog
    How would we then re-enable them? Say i want to enable all my products in the DB.
  • If they were using the data mapper pattern, rather than active record, it would be a lot easier for them to change the SQL when these problems occur.
  • halane
    Hi Branko, thanks a lot for your blog . I know that this is offtopic, but I didn't know where to put it. I'm a newbie with magento and I'm almost done with my online shop ...the only thing that I can't achieve yet is to assign a different transactional email to each payment method, any clue about what I should modify?
  • brankoa
    Simply go to System > Cache Management and do a Rebuild on all.
  • This will disable the product in the EAV table but it will not do the following:

    Disable the product in the "flat" catalog table
    Update the "catalogindex" tables (for filter navigation)
    Update the category product index tables.. (for showing up in the category)
    Update the catalogsearch tables
blog comments powered by Disqus
Powered by Wordpress | Designed by Elegant Themes