Drupal – Delete all orders in Ubercart

I have created so many testing orders in the Ubercart during the development. So before i migrate the site to production, i have to clear all the testing orders. This could be done by deleting the order one by one through the View orders page.

But i got more than 100 testing orders and obviously the above method is not clever enough.

So i created the following delete_all_orders.php in the <drupal_root> folder
delete_all_orders.php

<?php
  include_once './includes/bootstrap.inc';
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  
  global $user;
  
  if ($user->uid == 1) {
    $result = db_query("select * from uc_orders");
    while($row = db_fetch_object($result)){
      //# uncomment below to view an order and exit
      //# usefull to write a query to only delete certain orders
      //print_r($row);
      //exit;
      print "deleting order $row->order_id\n";
      uc_order_delete($row->order_id); // comment this out for testing
    }
  } else {
    print "Only Administrater could deleter orders.";
  }
?>

 

Now you can delete all the orders using the administrator account to access the following URL.

 

Done =)

Reference: delete all orders

Advertisements

6 thoughts on “Drupal – Delete all orders in Ubercart”

  1. FAIL!!!!!

    Would like to remove all of the test orders from a Ubercart database by using the empty table command in phpMyAdmin. Are the following tables the correct ones for this application? Or are there some that were missed? (Uber 1.6 – Drupal 5.12)

    1) uc_orders
    2) uc_order_comments
    3) uc_order_admin_comments
    4) uc_order_log
    5) uc_order_products
    6) sequences – change uc_orders_order_id back to 0

    And backup the database for insurance.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s