Custom Reports with Table Wizard and Ubercart

I've had a few people request custom reports that Ubercart does not have built in. Fortunately, thanks to the Table Wizard module, it's not hard to create them!

Required Modules:

  • Ubercart
  • Table Wizard
  • Views
  • Schema (required by Table Wizard)
  • Views Bonus (for Excel output)
  • Views Calc (to do calculations on views)

Step 1
Install and enable the required modules. If you're not familiar with how to do this, you should probably start with some more basic Drupal tutorials.

Step 2 - Setting up our Tables
In this example we will create a "sales by country" report. The first thing we need to do is go to the Table Wizard page and let it know which tables we want to work with. The table wizard page is at admin/content/tw

Click "Add Existing Tables" and add uc_orders and uc_countries. Now views will be able to see these two tables.

However, we do need to create a "relationship" between these two tables. So click on "analyze" next to uc_orders and scroll down to billing_country field and select "available key" checkbox. Save it. Now we can use the billing_country as a relationship.

Go to content management -> table wizard -> relationships. Add a relationship between uc_orders.billing_country and uc_countries.country_id and click "add"

Step 3 - Creating the View
Now we're ready to add a view. Go to site building -> views and add new view. From the view type, select uc_orders. You can name it sales_by_country or whatever you like.

Select country_name and order_total as the fields. Add a filter for uc_orders.order_status to complete.

Now, finally, select the style and select Views Calc table. Check "display calculation" for order total. Select "sum". Select "country" as the grouping field.

That's it! You're done. you've created a custom report for ubercart!

Recent comments