Adding custom fields to checkout and order panes

Posts: 67
Joined: 02/20/2008

I'm working on a site where I need to add some custom fields to the checkout and order panes and then have the data from those fields added to the customer and admin notice templates, and I have a couple questions:

  • I did some searching on adding tokens, and I found a couple posts with differing suggestions. This one mentions adding uc_order_token_list() and uc_order_token_values() functions to my module from uc_order.module. If I do that, do i have to keep all the definitions that are there and add my own, or can I just put my own in the function, and it will add them to the ones that already exist?

    Then, this post says I can just access the $order object directly in the template itself. Is it six of one and 1/2 dozen of the other? The only time I will be using these extra fields is in the checkout and order forms as well as the email templates.

  • I've been reading through the Lead Tracker module for a few hours now, and I just want to make sure I have this hook calling order for saving the data correctly understood (I had a whole question written on how the lead_source field gets converted to arg1->lead['source'], but I figured it our right before I submitted this post).
    1. hook_checkout_pane() displays form as defined in the callback parameter. This form has an ID value that is used to define the callback function name.
    2. The callback form uc_checkout_pane_paneID() where$op = 'view' is called to display the pane and add the new fields to the checkout page.
    3. On form submission, uc_checkout_pane_paneID() is called where $op = 'process'. At this point, form data is in $arg2, and you have to move it manually to $arg1, which is the order object.
    4. hook_order() is called where $op = 'save', and this is where you write your code to write the data to the database.

    Do I have that correct?

    By the way, thanks for the Lead Tracker module. I would still be thrashing around in the dark without that as an example.

    Thanks.

Posts: 67
Joined: 02/20/2008

OK, I've been looking at the Lead Tracker some more, and I thought I understood the adding of the data to the $order object, but now I'm not sure. What's confusing me is this code:

    case 'process':
      if ($arg1->lead['source'] !== t('Please select one...')) {
        $arg1->lead['source'] = $arg2['lead_source'];
      }
      if ($arg1->lead['source'] == t('Other source')) {
        $arg1->lead['other'] = $arg2['lead_other'];
      }
      return TRUE;

As I read it, this seems to indicate that there is already data in $arg1->lead_['source'], even before the data is put into it from $arg2. So am I incorrect in step 3 above? Is the data already in $arg1 when the form is first submitted? Or am I correct that this is where the data from the custom pane has to be manually added to $arg1 so it is saved as part of the $order object?

Thanks.

Posts: 67
Joined: 02/20/2008

While I'm still at it, I'm having a heck of a time trying to see the contents of the $arg1 and $arg2 two objects. Shouldn't I be able to use something like print_r() or dpm() (from the devel module) when $op = 'process' to see the contents of those objects?

Posts: 67
Joined: 02/20/2008

I've been able to work my way through my other questions, but now I have one more. According to Checkout documentation, the review $op is "Expected to return a string containing HTML output that will be dropped into a div. $arg1 is the current order object." However, when i look at the Leads sample module, it looks like an array is returned instead:

    case 'review':
      if ($arg1->lead['source'] != t('Please select one...')) {
        $review[] = array('title' => t('Site found through'), 'data' => $arg1->lead['source'] == t('Other source') ? check_plain($arg1->lead['other']) : check_plain($arg1->lead['source']));
      }
      return $review;

Which is it? If I use this format above for multiple fields, do I return one array for each piece of data? Or should this be an $output variable where I append HTML for each piece of data?

Thanks.

Posts: 5625
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

It looks like the answer is both. You can simply return a string, and it will be displayed in the div. However, you can also return an array of arrays like the example above so the information will be displayed in a table. The 'title' key will be the bolded text on the left and the 'data' key will be the text on the right.