Modify Ubercart invoice template and sort by SKU

I needed to modify the Ubercart invoice template. This invoice template appears to the user online and in email and is also used by the store admin to review/print/email/etc. invoices.
I needed to do some light modifications like; modify "Products on order:" to list products one per line as well as sort products by model (a SKU in my case).

  1. Changing the general template is easy, info about the templates files can be found here:
    • info on Ubercart 2.3.x:
      • You can set template file to use @: /admin/store/settings/orders/edit/basic
      • But to use and additional template file you need to use a custom module to define the ?? hook. I thought it easiest to just modify the uc_order-customer.tpl.php file.
      • Note: I use Garland as an Admin theme, so would need to need to put the template files there to override the default uc_order/template files.
    • info on Ubercart 1.x:
  2. To sort by SKU/model I had to use some PHP action:
    • Right after:
      <?php if (is_array($order->products)) {
      $context = array(
      'revision' => 'formatted',
      'type' => 'order_product',
      'subject' => array(
      'order' => $order,
    • I added:
      // function to compare 2 objects by 'model' attribute
      function model_cmp($a, $b)
      if( $a->model == $b->model ){ return 0 ; }
      return ($a->model < $b->model) ? -1 : 1;
      // sort the product array by model
      usort($order->products, "model_cmp");