8 replies [Last post]
Øyvind's picture
Offline
Cool profile pic award.
Joined: 08/10/2007
Juice: 35
Was this information Helpful?

Hi,

I've been a long time fan of just hacking stuff to make it work for each individual site because of tight deadlines, but now I decided I wanted to make a general Ubercart theming module which tweaks and styles the Ubercart checkout that I can use on my sites and at one time maybe even put on drupal.org.

It's been great so far, but I'm now at the checkout complete page and I can't find a single decent way to theme or alter the output on that page.

It seems to me you didn't add a theme function here because of the ability to set an alternate checkout completion page in the ubercart settings. Setting a different checkout completion page is not really an option for me because a lot of modules depend on the default one.

Is there some way of theming/altering the output of that page that I'm missing? Smiling

Btw, I'm using the latest recommended version of Ubercart 2 for Drupal 6.

Øyvind Strømsvik
Ny Media AS
oyvind@nymedia.no

Øyvind's picture
Offline
Cool profile pic award.
Joined: 08/10/2007
Juice: 35
Re: How to go about theming the cart/checkout/complete page?

My boss, he's the one everyone has a badge saying that they're not, just told me that we're launching this site in 3 hours and that I had to "make it work". Smiling

My normal hack for something like this would just be to throw something like

<?php
if (arg(0) == 'cart' && arg(1) == 'checkout' etc.

in my page.tpl.php file and use that.

I googled a bit and found hook_menu_alter now which I used like this:

function my_module_menu_alter(&$items) {
  $items['cart/checkout/complete']['page callback'] = 'my_module_checkout_complete';
}

my_module_checkout_complete() is just uc_cart_checkout_complete() copied with my additional theming throw in. This is surely an even worse hack as whenever you upgrade Ubercart you have to make sure uc_cart_checkout_complete() didn't change and if it did copy the changes, but at least it doesn't require me to go out of my module to theme the page. Smiling

Hoping someone will give me a proper way to accomplish what I'm trying to do. Until then it's hacked. Smiling

Øyvind Strømsvik
Ny Media AS
oyvind@nymedia.no

Øyvind's picture
Offline
Cool profile pic award.
Joined: 08/10/2007
Juice: 35
Re: Re: How to go about theming the cart/checkout/complete page?

Maybe instead of copying everything from uc_cart_checkout_complete() to my_module_checkout_complete() I can do something like this:

function my_module_checkout_complete() {
  $output = 'My theming goodness';
  $output .= uc_cart_checkout_complete();
  return $output;
}

It seems to be working and I don't have to worry about Ubercart being upgraded unless it's a complete rewrite.

I'll leave it like this until someone here with a bit more experience can take a look at it. Smiling

Øyvind Strømsvik
Ny Media AS
oyvind@nymedia.no

Øyvind's picture
Offline
Cool profile pic award.
Joined: 08/10/2007
Juice: 35
Re: How to go about theming the cart/checkout/complete page? [SO

I found the theme function I was looking for all this time. It was just to well hidden for me. Smiling

For anyone else wondering about the same thing:

uc_cart_checkout_complete() calls uc_cart_complete_sale() which in turn outputs theme_uc_cart_complete_sale(). So by overriding theme_uc_cart_complete_sale() you can change the look of the cart/checkout/complete page to whatever you want.

It would be nice if the messages wasn't already turned into html so that you could change their order etc., but at least I can accomplish everything I wanted now without the awful hacks I initially started out with. Smiling

Øyvind Strømsvik
Ny Media AS
oyvind@nymedia.no

BayerMeister's picture
Offline
Joined: 07/21/2009
Juice: 197
Re: Re: How to go about theming the cart/checkout/complete page?

Thanks for your thread. Glad I'm not the only one who went through this.
I however need the order_id at least in my theme_uc_cart_complete_sale. It comes in within the $message, but I find it awful to parse for "your order ID is %d".

I think this must have a simple answer, because I cant imagine building up a checkout completion page without the knowledge of what was sold. Maybe you have an idea or maybe someone else?

Thanks, Richard G.

P.S.: The parsing would not be such a shame if the message wasn't so flexible, translatable and reflecting if the user was a new one or logged in already. And knowing that there was a token [order-id] in place before...! I WANT THAT ID! Smiling

achton's picture
Offline
Joined: 05/04/2010
Juice: 37
Re: How to go about theming the cart/checkout/complete page? [SO

Unfortunately, it seems to require a (small) patch to uc_cart: http://drupal.org/node/596740

tHe_WooKiE's picture
Offline
Joined: 11/24/2011
Juice: 7
Re: How to go about theming the cart/checkout/complete page? [SO

I know this thread is old, but in case this information is useful...

You can edit most of the messages output at cart/checkout/complete by going to admin/store/settings/checkout/edit/messages

additionally as already noted if you really want to change it drastically you can use theme_uc_cart_complete_sale().

ddrum's picture
Offline
Joined: 03/13/2012
Juice: 5
Re: How to go about theming the cart/checkout/complete page? [SO

I realise this is quite an old topic but having just visited this myself I'd like to offer my solution to the community. This is for Drupal 7 and Ubercart 3.

Simply alter the 'Message Header' field at admin/store/settings/checkout and include something to be picked up by str_replace (i used PRINTLINK). So my 'Message Header' field looks like this:

<p>Your order is complete! Your order number is <b>[uc_order:order-number]</b>. Click here for a PRINTLINK.</p>

After that, open up your theme template.php and add the following code:

/**
* Themes the sale completion page.
*
* @param $variables
*   An associative array containing:
*   - message: Message containing order number info, account info, and link to
*     continue shopping.
*
* @ingroup themeable
*/
function yourtheme_uc_cart_complete_sale($variables) {
  if(variable_get('uc_cust_view_order_invoices', TRUE)){
    $link = t('printable invoice');
    $printlink = array(
      '#markup' => l($link, 'user/' . $variables['order']->uid . '/orders/' . $variables['order']->order_id . '/print', array(
        'html' => TRUE,
        'attributes' => array(
          'onclick' => "window.open(this.href, '" . t('Invoice') . "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=480,left=50,top=50'); return false;",
        ),
      )),
    );
  }
  // PRINTLINK must match whatever text token you have in the message header field at admin/store/settings/checkout
  $variables['message']=str_replace('PRINTLINK',drupal_render($printlink),$variables['message']);
  return $variables['message'];
}

The $printlink structure is taken from function uc_order_view of uc_order.module. It's not the most elegant solution in the world but given the variables passed to theme_uc_cart_complete_sale by uc_cart_complete_sale its acceptable.

edit: Actually just realised I've posted this in the wrong place. This reply concerned getting a link to the printable invoices in the order complete page.

merzikain's picture
Offline
Joined: 06/20/2012
Juice: 3
Re: How to go about theming the cart/checkout/complete page? [SO

I'm not sure if what I'm getting ready to say was not the case back when this was created but for anyone who is looking to theme this page themselves, here's the info:

The theme_uc_cart_comlpete_sale() function comes with two arguments, $message and $order. $order is the order object, which includes the order id and every other bit of information you could possibly want from the order that was just completed. No need for any regexp or patches or anything.

Just be sure when you create your theme's version of the function you include both arguments:

function mytheme_uc_cart_complete_sale($message,$order){
...
}