I have OpenCart v1.4.9.3 installed. I have an existing database. I am going to create a new database and new OpenCart install using an export of my existing database. I want to reset order, invoice, customer counters etc.

I want to delete everything else in the database and reset all counters orders, invoices, customers, etc.

This is what I was planning on doing.... is this right?
1) Export existing database using PHP Admin
2) Import existing database to new database using PHP Admin
3) Delete all products that I no longer want
4) Delete all product categories that I no longer want
5) Delete all manufacturers that I no longer want
6) Run PHP delete_demo_data.php script (below)

I was planning on running the delete_demo_date.php PHP Script that was posted earlier in this post

Two questions:
1) Is this a comprehensive list of all OpenCart tables that should be TRUNCATED for OpenCart version 1.4.9.3? If not what tables should I add?
2) I understand that TRUNCATE TABLE opencart_table will reset the counter in the table (is this correct?)

step 6.) will wipe out all the data in the tables listed in the script. so, possibly your steps above might be useless.

@ this script
opencart should really offer 3 types of data setup:
1.) full demo as of now
2.) data for only the sections that setup up configs and such.
3.) an option to #2 where you can choose your countries and zones. Erasing all those that you don't need can be a bit tedious.

Use the script above.
You can always re-enter the products you want. (That is if you are using the demo data).

Backing up and then importing is not that hard but requires excel or similar software. You will also need to watch out how the product numbers change and their relations to other tables and such. This takes time and you would normally end up being faster with just redoing the products and such.

Thank you for your reply. The whole point of my post was that I already have the products in my existing database and want to import those products and all other related (product) tables to the new database. Sorry but, reentering the products is not a valid option. Way too time consuming

Again, my main challenge is understanding how to "reset" the counters in the customers, orders, invoices etc. tables and identifiying all the tables that need to have their counters reset.

well identifying which tables need to have the counters reset is probably easiest done by checking which have auto increment set.

But as SapporoGuy said, matching product numbers and their relations to other tables can be quite tricky.

I personally would avoid changing anything to do with orders and invoices, except for invoice and order numbers, their relation to product id's is gonna be tricky to re-match should you truncate product id's.

Here is the scenario:
You dump your db, open it in excel, count all the number of products you have (by hand), copy that number to the auto-increment part in the db dump and paste it in (forgot if you need to +1 or not).

So, if you had lets say 300 products, your db was counting at 755.
You now have it reset to 300.
Next product that you make will nicely be product_id 301 .... perfect!!!! touch down.

errr, referee calls a penalty -- 15 yeards for use of leverage.
Sorry, no touch down.

What happened?
You made a NEW product with product_id of 301.
The is already a product with product_id in the db.

So, you can't just truncate the db and hope to start with fresh numbers.

You have to use excel and be careful about changing your numbers.

IF this were the settings table.
You could truncate the table.
Erase all the setting_id(s), need to keep the column blank by using '' (double single quotes) and then import into the table. All the data will go in starting from 1. This should have been done but it takes the time to drink half a coke-a-cola. Oh well.

Thank you for your post. I think, and I could be wrong, but it appears as though you are thinking that I want to reset the counter in the Product table. This is not true. I want to keep product ids as is. I am not changing the values in the opencart_product table.

This should be very simple, export the database via PHP Admin, import the database to the new database and TRUNCATE the correct tables (so that the counters are set back to 1). My challenge is really just identifiying all of the tables that I should TURNCATE.

So far I have identified:
opencart_customer
opencart_order
.... I am sure that there are more tables

The only tables that I am wanting to reset the counters are hopefully the orders, customers, invoices, etc.

I'm trying to get the script working locally but nothing is being deleted. I just get the echo output. Manually deleting or truncating in phpadmin works but I'd really like to get the script working. This is 1.4.9.4. All tables are prefixed with oc_. I've tried the script as is; tried changing the single quotes around oc_$table (in the truncate line) to striaght single quotes (thinking maybe the curly types weren't intentional...still new at php and sorting out the syntax). Anyone have an idea what I might be missing?

I have updated this to work with Opencart 1.5. All you need to do is place this file in the /upload file and access this file directly in your browser. Remember to delete this file once you have deleted the temp data.

Adding to mgirouard code to delete the temporary files installed with opencart:

image/data
images/cache
downloads
system/cache

the images/data and images/cache

Attachments

Tested for OC-1.5.0.5Warning Remove all catalog data and orders. Also remove product images and database cache.