Embed view in Ubercart catalog

By Jimmy Bonney | August 22, 2011

Magazines

Ubercart comes with a catalog that allows to display the different products in categories. This is a pretty nice and convenient way to browse through the different product families but for the product browsing itself, a list is much more easy to go through. The problem with the catalog list / table default display, is that it doesn’t use Views but rather a default call to the ubercart table display.

Fortunately, Ubercart makes it easy to override this default call. For this, one just needs to define a themable function (theme_uc_catalog_products($products)) in template.php in order to make a call to a predefined view with the function views_embed_view.

File template.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
function mythemename_uc_catalog_products($products) {
  if (!$products) {
    $output .= '<div class="no-products">'. t('No products are available in this category.') .'</div>';
    return $output;
  }
  else {
    if (variable_get('uc_catalog_grid_display', FALSE)) {
      return theme('uc_catalog_product_grid', $products);
    }
    else {
      $products_id = implode(",", $products);
      return views_embed_view('uc_products','page_1', $products_id);
    }
  }
}

References

As often, great content was available online. Here are some of the resources that I used to achieve using views in the catalog display.



For the time being, comments are managed by Disqus, a third-party library. I will eventually replace it with another solution, but the timeline is unclear. Considering the amount of data being loaded, if you would like to view comments or post a comment, click on the button below. For more information about why you see this button, take a look at the following article.