If you are using uc_popular module then the snipplet below will be a match for it, otherwise please change the function that points to uc_popular module.

The snipplet below is for theming ubercart default product page into a switchable list view and grid view. The switch will be done using jquery.

The jquery for switching the grid to list view is available as a block in uc_popular module. You can download the beta version of the module in the attachment below this post.

Now put the following function to your template.php

// Template For product Grid

function phptemplate_uc_catalog_product_grid($products) {

  $count = 1;
  $context = array(
    'location' => 'catalog-grid-product',
  );

$output .= '';

  foreach ($products as $nid) {
    $context['subject'] = array('node' => $product);
	
// preparing for the image link and image cache used is uc_thumbnail

	$product_node = node_load($nid);
	
	$titlelink = l($product_node->title, "node/$nid", array('html' => TRUE));
	$imageminilink = '';
    	  $thickbox = array(
	  'html' => TRUE,
	  );
	
	if (module_exists('imagecache') && ($field = variable_get('uc_image_'. $product_node->type, '')) && isset($product_node->$field) && file_exists($product_node->{$field}[0]['filepath'])) {
      $imageminilink = l(theme('imagecache', 'uc_popular_large' , $product_node->{$field}[0]['filepath'], $product_node->title, $product_node->title), "node/$nid", $thickbox);   
    }

	$output .= '';
	
	$output .= '';
	$output .= $imageminilink;
	$output .= '';
	
	$output .= '';
	$output .= '' . l($product_node->title , 'node/'.$product_node->nid ) . '';
	$output .= '' . $author->name . '';
	$output .= '';
	
	$output .= '';
	$output .= '' . substr($product_node->teaser, 0 , 230) . '';
	if ( $product_node->sold_count) {
	$output .= '' . $product_node->sold_count . ' purchases';
	}
	$output .= '';
	//drupal_set_message(print_r($product_node));
	$output .= '';
	$output .= '' . uc_currency_format($product_node->sell_price) . '';
	if (module_exists('fivestar')) {
	$output .= '' . fivestar_widget_form($product_node) . '';
	}
	$output .= '';
	
 	$output .= '';
}
$output .= '';
  return $output;
 }

Then after downloading and enabling the uc popular module, please enable the module switching block. Now if you got everything right, you can have a dynamic switchable view from a list view to a grid view without reloading the page.

Also the snipplet is capable to integrate with uc_best_seller and fivestar widget.

AttachmentSize
Package icon uc_popular.zip8.91 KB