I’ve been dabbling around with OpenCart lately after needing to take a much needed break from Magento. One of the things I needed to do was wipe out all of the sample data which was added during the initial setup of the catalog.
A quick search online lead me to a thread on the community forums. The technique described there worked perfectly, but since it wasn’t totally portable, I hacked up a little script which improves things a bit. Namely:
- Brings everything into PHP for easier refactoring should tables be added/removed or have their names change
- Uses the native OpenCart API so it’s guaranteed to work so long as their DB libraries work
- Uses your DB configuration (read: no find/replace for that annoying DB prefix)
- Use
TRUNCATE TABLE ...rather thanDELETE FROM ...to reset the auto increment counter.
You can find the source in this Gist on Github.
To use it, just call:
php destroy-sample-data.php -p /path/to/your/opencart/directory
If you forget to pass in the -p option, it assumes the current working directory. Note: If that’s how you’re doing it, you’re doing it wrong. Hopefully I shouldn’t need to explain why…







