Theme Ubercart Shopping Cart Block

So, you have a kicking Drupal Ubercart site but you don't like the way that the shopping cart block works. Maybe you want it on one line. Maybe you want to change the structure of it? How can it be done?

A little bit of investigation leads us to line 751 of uc_cart.module


function theme_uc_cart_block_summary($item_count, $item_text, $total, $summary_links) {
$context = array(
'revision' => 'themed-original',
'type' => 'amount',
);
// Build the basic table with the number of items in the cart and total.
$output = '<table class="cart-block-summary"><tbody><tr>'
.'<td class="cart-block-summary-items">'. $item_text .'</td>'
.'<td class="cart-block-summary-total"><label>'. t('Total:')
.'</label> '. uc_price($total, $context) .'</td></tr>';

// If there are products in the cart...
if ($item_count > 0) {
// Add a view cart link.
$output .= '<tr class="cart-block-summary-links"><td colspan="2">'
. theme('links', $summary_links) .'</td></tr>';
}

$output .= '</tbody></table>';

return $output;
}


This is the part of the file that is making the display of ubercart for your site. Want to change it? No problem. Just create a new entry to your template.php file (in your site template) and when it displays it will override the display of the theme to your requirements. I have included a simple one to put the shopping cart into 1 line; but the options are only limited by html!


Example:
function YOURTHEME_uc_cart_block_summary($item_count, $item_text, $total, $summary_links) {
$context = array(
'revision' => 'themed-original',
'type' => 'amount',
);
// Build the basic cart into 1 line
$output = '<table class="cart-block-summary"><tbody><tr><td>'.$item_text .' <label>'. t('Total:').'</label> '. uc_price($total, $context).'</td><td>';

// If there are products in the cart...
if ($item_count > 0) {
// Add a view cart link.
$output .= '<td>'.theme('links', $summary_links).'</td>';
}

$output.= '</tr></tbody></table>';
return $output;
}

(Don't forget to change the name from YOURTHEME to the actual code name of your theme!)

Add comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.