Browsing ubercart catalogs with custom views capabilities

More or less, this is the idea already posted here, from me. Here, I will try to more explainative.

Ubercart catalog:

Pros: Has very nice browsing features, thumbnail catalog pictures. Also, it shows in a nice way catalog hierarchy above products.

Cons: The way products are shown, is really difficult to customze.

 

Views:

Pros: "views"...

Cons: Nothing that comes to my mind.

 

So we want to have both pros but no cons. :)

  1. Let's assume that we have a custom theme, called custom_theme.
  2. Create a view, for our purposes let's call it "catalog_inner", which has a term id as an argument. There is no need creating page or something else inside the view. "Default" can do our job.
  3. Find the file "/sites/all/modules/ubercart/uc_catalog/uc_catalog.pages.inc" and copy the function theme_uc_catalog_browse to our own module, but rename it to custom_theme_uc_catalog_browse, considering out theme prefix.
  4. Find the follwing code inside our function:

 

  if (count($catalog->products)) {
    if (count($links)) {
   .... .... ....
    $output .= $catalog->description;
    $output .= theme('table', array(), $cat_rows, array('class' => 'category'));
  }
 

 

It is the last "if", so it will not be difficult to find. According to the previous code, the idea goes like this:

If we have products inside the specified term id, we show the subcategories, if they exist, as small labels [=small_label_category_list] and after that we show all the products [=product_list]. If there no products to show, we show all subcategories, 3 per row, and theis thumbnail images [=big_category_list].  Change all the above code to the follwing one:

 

    // As before, we preproccess all subcategories to show them 3 per row
    $columns = variable_get('uc_catalog_category_columns', 3);
    $cat_rows = array();
    $row = array();
    $i = 1;
    foreach ($child_list as $cell) {
      $row[] = array('data' => $cell, 'class' => 'category');
      if ($i % $columns == 0) {
        $cat_rows[] = $row;
        $row = array();
      }
      $i++;
    }
    if (count($row) > 0 && count($row) < $columns) {
      if (count($cat_rows) >= 1) {
        $row = array_merge($row, array_fill(count($row), $columns - count($row), array('data' => '&nbsp;', 'class' => 'category')));
      }
      $cat_rows[] = $row;
    }
    $output .= $catalog->description;
    $output .= theme('table', array(), $cat_rows, array('class' => 'category'));
 
    // We print the description of out category
    $output .= $catalog->description;
 
    // We print the results from our view. Notice that the third argument is the term id, as a view argument
    $output .= views_embed_view('catalog_inner', 'default', $catalog->tid);
Now the idea has changed, and we always show the "big_category_list" and then the "product_list", in any case, without having to differentiate the situtation for categories with or without products. A live example can be shown here.
 
 

 

 

 

Comments

Great post! I bookmark this

Great post! I bookmark this page. Thks.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

Linked In Profile