magento | bulk update products prices


if you need to update all products price, rather than going through the admin panel to update each product or buy a extension to do the job, you can simply update it directly in the database using a SQL query after adjusting it to your needs, follow the guide below to update some or all products price:

1- backup your magento database first if you don't know how check documentation.
2- gain access to your site db either through a tool like phpmyadmin or directly from terminal
3- Adjust price field data type to insure there would be no out of range sql error by running this SQL script:
ALTER TABLE catalog_product_entity_decimal MODIFY value BIGINT;
4- Test b4 running the update and check if the result is exactly what you need to do:
All Records:
SELECT value,value*1.15 as '15%' from catalog_product_entity_decimal;

Single Record:
SELECT value,value*1.15 as '15%' from catalog_product_entity_decimal where catalog_product_entity_decimal.entity_id=12652;

5- below is the SQL you will execute, change it to match your needs, in this case i am just adding 15% for all products price
All Records:
UPDATE catalog_product_entity_decimal SET catalog_product_entity_decimal.value = ROUND(catalog_product_entity_decimal.value*1.15,2);
Single Record:
UPDATE catalog_product_entity_decimal SET catalog_product_entity_decimal.value = ROUND(catalog_product_entity_decimal.value*1.15,2) where catalog_product_entity_decimal.entity_id=12652;
6- go to magento cli and run Reindex and clear cache:
bin/magento indexer:reset
bin/magento indexer:reindex
bin/magento cache:flush

Source:

Comments