Ubercart, Webform Checkout Panes and Views

Say you build a Drupal 6 website with Ubercart. You wanted to ask some extra questions during checkout, so you used Ubercart Webform Checkout Pane to add an extra panel with a custom form that users would fill during checkout.

The data is stored and displayed alongside the order - which is just great. Later in time you start using Ubercart Views to create your own view displaying Ubercart orders. Unfortunately, the Webform module does not provide views integration. The proper way to do this with Views would be to expose the webform and webform_checkout_pane tables using the Views API ; then linking in those tables to your view of orders using relationships.

Unfortunately, due to the way the Webform module stores its data, this is not possible, as is explained in issue #680386: Views integration for the webform_submitted_data table. If you are starting something new then probably your best bet is to stop using Ubercart Webform Checkout Pane and use Ubercart CCK Checkout Pane instead.

However if you are stuck with Ubercart Webform Checkout Pane and performance is not crucial, there is another way to do this : by creating a View that displays only you webform data, and using Views View Field to include the result into the main view of orders. Implementing this approach requires jumping through a few hoops :

  1. First you have to expose the uc_webform_pane_submissions and webform_submitted_data tables to Views. The simplest way to do this is to install the Table Wizard module. Once installed :
    • go to Content Management >>Table Wizard ;
    • Under 'Add existing Table' select 'uc_webform_pane_submissions' and 'webform_submitted_data'. Untick 'Provide Default View' and do 'Add Tables'. ;
    • Edit the 'webform_submitted_data' table, and leave only 'sid' in the PK (Primary Key) and Foreign Key columns ;
    • Edit the 'uc_webform_pane_submissions' table, and leave only 'sid' in the PK and Foreign Key columns ;
    • Go back to the Table Wizard and go to the 'Relationship' tab. There, add a new relationship selecting 'uc_webform_pane_submissions.sid' for the base field and 'webform_submitted_data.sid' for the corresponding field. Leave the relationship as automatic and save it.
  2. Next create a new view. For the type of view select 'Database table uc_webform_pane_submissions'. In this view :
    • Add a filter on 'uc_webform_pane_submissions: nid' so that this is equal to the Node Id of the webform you want
      to display. To work out the Node Id, go to Content Management>>Webform and look at the edit
      link for the webform - this will give you the node id ;
    • Add the field 'webform_submitted_data: data' to your view ;
    • Finally, add an argument to the view on 'uc_webform_pane_submissions: order_id' ;
    • Save the view.
  3. Now go back to editing the initial view - the view of orders in which you wanted to include the webform data.
    • Make sure that 'Order id' is included in the list of fields - we need it for token replacement. If you don't want it
      displayed, you can select 'Exclude form display' ;
    • Add a 'View' field (you need the Views View Field module for this) ;
    • For that field, select the View you just created and in the 'Arguments' field enter '[order_id]'.

That's it. This does feel quite complicated for something that should be simple. The lack of integration of Ubercart and views, and the way the Webform data is stored make it so. Hopefully this is a technique we will only need to use on legacy sites that use this particular combination of modules.