Providing a clean database is critical when we move to production. During the development phase, testers and developers may add test data for products, customers, orders, items etc for unit testing and system testing. When the website is set to go live, we need to remove the test data.

Clearing the data manually is a tedious and a ‘not-a-proper-way’ of cleaning the database.

The codes below clear the data automatically reducing the effort of the developers and also providing a clean database for production.

Just in case, please take a backup of your test DB before applying this code.

Delete Cart Items:

Delete Products:

Delete Orders:

Code to delete the Orders, Invoice, Credit Memo and Shipment programmatically in Magento 2:

Delete Customers:

Hope the code was useful. Please share us your feedback and comments.

Be the first to Know

Subscribe to our blog to get the latest articles directly to your inbox.


Ready to drive online revenue

Get In Touch

Leave a Reply

Be the First to Comment!