have the following code in my template.php, but not sure how to modify the output of drupal_render($form). right now it just outputs as a table. I changed the #theme type in the items array to patzz and created my own theme function on top on line 172. what am i doing wrong?

function msk_theme_patzz($variables) { return 'asdf'; }                                                                                                             
173    
174 function msk_theme_uc_cart_view_form($variables) {
175   $form = $variables['form'];
176   drupal_add_css(drupal_get_path('module', 'uc_cart') . '/uc_cart.css');
177  $form['items']['#theme'] = 'patzz';
178    
179 //  print_r($form['items']);
180   $output = '<div id="cart-form-products"> XXXX'   
181           . drupal_render($form['items']) . 'YYYY</div>';
182    
183   foreach (element_children($form['items']) as $i) {
184     foreach (array('title', 'options', 'remove', 'image', 'qty') as $column) {
185       $form['items'][$i][$column]['#printed'] = TRUE;
186     }                    
187     $form['items'][$i]['#printed'] = TRUE;         
188   }                      
189    

Comments

patoshi’s picture

i got to the point where I can see how the table is being generated by the #type setting ? (is that wats its called?) where it equals to tabir_table ... what other options are there? i want to make it a list if possible...

patoshi’s picture

wow this is crazy... alot of ubercart sites and themes that ive browsed doesnt have a custom cart page.... im guessing alot of ppl had the same problem and just gave up and stuck with the default one.

mcfilms’s picture

You are probably not getting much of a response because few people have made the jump to D7 with Ubercart yet. That, and what you are doing seems pretty advanced.

I can tell you that in D6 and UC 2 I was able to somewhat fine-tune the cart presentation on the site at http://skinglowmd.com. I was able to add some DIVs and create more of a two-column layout with section headers by customizing the file uc-cart-checkout-form.tpl.php and adding a bunch of css.

A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com

patoshi’s picture

thanks for the heads up... your right maybe thats why i cant find anything on it. well i've been trying to figure out how this is working by following the functions that go all the way to table render and drupal render.... so far im kinda stumped on how to manipulate the layout.... would be great if they just used a list format... tables is totally not cutting it...i can understand the semantics of it, but hell would be great to give the option to output as a list.

babusaheb.vikas’s picture

Hi,

For theming the cart page in drupal 7 ubercart you can create a module in drupal7 and can put function :------

function _tapir_table_alter(&$table, $table_id) {

// Modify the display of the cart table.
if ($table_id == 'uc_cart_view_table') {
// New column in the cart table.

// For each product or product kit line of the cart.
foreach ($table as $key => &$value) {
if (is_numeric($key) && isset($value['nid'])) {
// Set an empty area.
$value['attributes_in_cart'] = NULL;

// PUT YOUR PHP CODE HERE ...............................................

$value['desc'] = array('#markup' => $attrib_val );

// For product lines, we must mark the cart_item_id that belongs to this line.
}
}
}
}

Vikas kumar

merzikain’s picture

I realize this is a 4 year old topic but I think it would be helpful to have another answer to this question.

If you're like me and you just wanted to get rid of that aweful, archaic table in favor of something modern, you can use my method. It utilizes the theme function op was using and doesn't require a new module to implement.

function YOURTHEME_uc_cart_view_form(&$vars){
	$form = &$vars['form'];

	$output = '<div class="uc-default-submit">';
	$output .= drupal_render($form['actions']['update']);
	$output .= '</div>';
	$form['actions']['update']['#printed'] = FALSE;
	
	$table = drupal_render_children($form);
	$table = str_replace(array(
		'<table class="sticky-enabled">','</table>',
		'<thead>','</thead>',
		'<tbody>','</tbody>',
		'<tr','</tr>',
		'<td','</td>',
		'<th','</th>',
	),array(
		'<div class="cart-item-list">','</div>',
		'','',
		'','',
		'<ul','</ul>',
		'<li','</li>',
		'<li','</li>',
	),$table);
	$output .= $table;
	
	return $output;
}

It's the fastest/easiest way to turn the cart view table into a modern html list that you can easily style however you want. I also added a jQuery script to fix/clean certain things about the table layouts that I wasn't unsatisfied with:

...
if($('#cart-form-pane').length){
	$('#cart-form-pane').prepend('<h1>Shopping Cart</h1>');
	$('#cart-form-pane table > ul:first-child').addClass('head');
	$('.cart-item-list > ul:first-child > li:nth-child(1)').addClass('remove').text('');
	$('.cart-item-list > ul:first-child > li:nth-child(2)').addClass('image').text('');
	$('.cart-item-list > ul:first-child > li:nth-child(3)').addClass('desc').text('Products');
	$('.cart-item-list > ul:first-child > li:nth-child(4)').addClass('qty');
	$('.cart-item-list > ul:first-child > li:nth-child(5)').addClass('price');
	$('.cart-item-list > ul:last-child').removeClass('even').removeClass('odd');
	$('.cart-item-list > ul.odd, .cart-item-list > ul.even').addClass('cart-item');
	$('.cart-item-list > ul:last-child').addClass('subtotal').prepend('<li class="remove"></li><li class="image"></li><li class="desc"></li><li class="qty"></li>');
	$('.cart-item-list > ul:last-child > li:last-child').addClass('price').removeAttr('colspan');
}
...

Now this solution isn't pretty nor likely the best solution, however it is, as I stated, fast and easy.

vitalijus.trainys@gmail.com’s picture

I realize this is a 4 year old topic, but there is another method - THEME_tapir_table() function. This function returns rendered table, by calling theme('table'). If You replace logic and returned value of this function, You can get own cart view display.

RKopacz’s picture

I know this is old, but thanks so much for posting it. I have a site that I migrated a while back from 6 to 7, and we just went with Ubercart rather than Commerce to make the upgrade simpler. I am now making it responsive and this absolutely did the trick. I am indebted!!

TheWrench’s picture

Merzikain thank you - it works for me as well.