17 replies [Last post]
cfab's picture
Offline
Joined: 06/30/2009
Juice: 70
Was this information Helpful?

Hi there,

I'm facing this question since I want to customize products list rendering. I've a view called "uc_products" but it only controls the total products list, what I want is to override the products list of a single category in the catalog.

Is there a way to do it with Views, except on reconstructing entirely the catalog? I mean, is there a way to change just the categories' products list and to keep the catalog navigation untouched?

Thanks in advance!
cfab

jsims281's picture
Offline
Joined: 05/28/2009
Juice: 69
Maybe...

If I understand correnctly, you might want to look at adding arguments to your view, and feeding it the category you want to display?

See http://drupal.org/node/54455

cfab's picture
Offline
Joined: 06/30/2009
Juice: 70
Re: Maybe...

Nope, my problem is that I don't know how to use a view instead of uc_product_table output.

cfab's picture
Offline
Joined: 06/30/2009
Juice: 70
Re: How to use Views instead of uc_product_table?

Am I the only one to want to customize the standard products list table???

arpieb's picture
Offline
Joined: 10/28/2009
Juice: 81
Re: How to use Views instead of uc_product_table?

I'm right there with you. I need to add several columns to my category product list (some of which are custom CCK fields I have added to the Product content type) in order to get the look my client needs. I'm building a parts book for cars, so need the following columns in the category listing (again, some are custom fields):

  • Replacement Part No (mapped to "title", standard UC column)
  • OEM Part No (CCK text field)
  • Description (mapped to "body")
  • Qty Required (CCK integer field)
  • Unit price (standard UC column)
  • Add to Cart (standard UC column)

I'm really surprised there is no way to toggle product fields for display on the catalog pages as well as the product pages. In fact, at admin/store/settings/products/edit/fields there is only a subset of fields available. In the uc_product_table() function only a handful of fields are even options (image, name, list_price, sell_price, uc_cart):

/**
* Display product fields in a TAPIr table.
*
* Display image, name, price, and add to cart form.
*/
function uc_product_table($args = array()) {
  $enabled = uc_product_field_enabled();
  $table = array(
    '#type' => 'tapir_table',
    '#attributes' => array(
      'class' => 'category-products',
    ),
    '#columns' => uc_product_table_header(),
    '#rows' => array(),
  );

  $context = array(
    'revision' => 'themed',
    'type' => 'product',
    'class' => array('product'),
  );
  $options = array('label' => FALSE);

  foreach ($args as $nid) {
    $data = array();
    $node = node_load($nid);
    if ($enabled['image']) {
      if (module_exists('imagecache')) {
        if (($field = variable_get('uc_image_'. $node->type, '')) && isset($node->$field) && file_exists($node->{$field}[0]['filepath'])) {
          $image = $node->{$field}[0];
          $data['image'] = array('#value' => l(theme('imagecache', 'product_list', $image['filepath'], $image['alt'], $image['title']), 'node/'. $node->nid, array('html' => TRUE)));
        }
        else {
          $data['image'] = array('#value' => t('n/a'));
        }
      }
    }
    $data['name'] = array(
      '#value' => l($node->title, 'node/'. $node->nid),
      '#cell_attributes' => array('width' => '100%'),
    );

    $context['subject'] = array('node' => $node);
    if ($enabled['list_price']) {
      $context['class'][1] = 'list';
      $context['field'] = 'list_price';
      $data['list_price'] = array('#value' => uc_price($node->list_price, $context, $options), '#cell_attributes' => array('nowrap' => 'nowrap'));
    }
    if ($enabled['sell_price']) {
      $context['class'][1] = 'sell';
      $context['field'] = 'sell_price';
      $data['price'] = array('#value' => uc_price($node->sell_price, $context, $options), '#cell_attributes' => array('nowrap' => 'nowrap'));
    }

    if (module_exists('uc_cart') && arg(0) != 'admin' && $enabled['add_to_cart']) {
      $data['add_to_cart'] = array('#value' => drupal_get_form('uc_catalog_buy_it_now_form_'. $node->nid, $node));
    }
    $table[] = $data;
  }

  if (!count(element_children($table))) {
    $table[] = array(
      'name' => array(
        '#value' => t('No products available.'),
        '#cell_attributes' => array(
          'colspan' => 'full',
        ),
      ),
    );
  }

  return $table;
}

Are views the way to go, or is there a module out there that allows this kind of mapping to be done, overriding the product page and category product lists? If no module exists, any idea if this would even be possible before I start going down that road? I've found two different set of TAPIr hooks documented so far, so don't even know which (if any of them) are accessible from a third-part module...

-R

cfab's picture
Offline
Joined: 06/30/2009
Juice: 70
Re: Re: How to use Views instead of uc_product_table?

Well, since it doesn't seem to be possible to use view in order to force a single category products list display, is there at least a way to display extra fields in this same list? I mean, a way without hacking Ubercart code...

stephthegeek's picture
Offline
Theminator
Joined: 10/20/2007
Juice: 575
Re: Re: Re: How to use Views instead of uc_product_table?

I really don't quite understand what you guys are trying to do that Views doesn't do... you can filter by any taxonomy term (catalog category) in a view, or use arguments to have it display a particular category based on path.

I always use Views on Ubercart sites because it gives you much more control over the catalog display than the default catalog from Ubercart, ie. displaying CCK fields or anything else along with Ubercart product elements, custom sorting, filtering, changing the way products are laid out, etc. This is a pretty common thing so there must be a disconnect in the description here. Can you be a little more specific about what's not working?

Gorgeous original Drupal themes (and Ubercart themes!) ~ Psst: more Ubercart themes on our new site

cfab's picture
Offline
Joined: 06/30/2009
Juice: 70
Re: Re: Re: Re: How to use Views instead of uc_product_table?

My concern is not to create views, this is easy, it's to use views AND to keep the catalog navigation system. Since the catalog nav system is hard coded, I can't figure out how to do, if you know of to do this, please share, that will make two happy guys! Eye-wink

stephthegeek's picture
Offline
Theminator
Joined: 10/20/2007
Juice: 575
Re: Re: Re: Re: Re: How to use Views instead of uc_product_table

Ahhh... I use http://drupal.org/project/taxonomy_menu for that Smiling

Or do you mean the in-page content, not the block? http://drupal.org/project/taxonomy_image (+ Views) will get you most of the way there, but if you need multiple levels of nesting then there's a tutorial floating around somewhere I've seen, but I've never needed to do that part.

Gorgeous original Drupal themes (and Ubercart themes!) ~ Psst: more Ubercart themes on our new site

cfab's picture
Offline
Joined: 06/30/2009
Juice: 70
Re: Re: Re: Re: Re: Re: How to use Views instead of uc_product_t

Yes, I mean in-page content.

[Edit ] : have you got the URL of this tutorial? I guess a clean hack will be the solution, I was hoping to avoid it but astonishly it seems I can't...
For the next version of UC, maybe a replacement of uc_product_table function by a view would be a good point.

stephthegeek's picture
Offline
Theminator
Joined: 10/20/2007
Juice: 575
Re: Re: Re: Re: Re: Re: Re: How to use Views instead of uc_produ

Yeah, I can look. But just to be clear that we're looking for the same thing, specifically which part are you having trouble recreating? Multiple levels of nested categories?

Gorgeous original Drupal themes (and Ubercart themes!) ~ Psst: more Ubercart themes on our new site

cfab's picture
Offline
Joined: 06/30/2009
Juice: 70
Re: Re: Re: Re: Re: Re: Re: Re: How to use Views instead of uc_p

Yes, I've trouble recreating the in-page UC Catalog navigation, in other words nested categories.

In fact, as I was looking for something simple, I've not thinking of that yet; all I knew is that giving a same path pattern (such as "category/%") a view can't behave differently, so it cannot display sub-categories grid one time (the nested categories) and products list another time. This is that last behavior I want to mimic.

Since the catalog has more than 1200 categories and considering my client will only have to add a taxonomy term (that's the most difficult part I can ask him to do, he's not a webmaster, just a seller), I need this to be set on time and after this automatically handled from taxonomy content.

The "ideal" solution would be, imho, the possibility of override uc_product_table call with a view output.
Other solution is to have a themeable function (with all fields included) for this display.

stephthegeek's picture
Offline
Theminator
Joined: 10/20/2007
Juice: 575
Re: Re: Re: Re: Re: Re: Re: Re: Re: How to use Views instead of

Heh, I think this last message actually got me more confused but I'll throw out what I know here anyway. By "nested categories" what I meant was the way taxonomy term images display by the category in the page, and you can drill down into each level. Are you talking about that or the subcategory navigation at the top?

I believe this is the article I'm remembering: http://www.commerceguys.com/resources/articles/123
Someone on IRC I was chatting with many weeks ago reported it as being the last piece of the puzzle to get their Views-based catalog behaving the same way as UC's.

Also you may be interested in using Views attachment displays so you can lump more than one display together (if that's what you meant by the two different types of product displays): http://www.agileapproach.com/blog-entry/the-views2-attachment-display

And have you seen this add-on that does exposed sorting/display types for UC views? http://drupal.org/project/uc_advanced_catalog

Gorgeous original Drupal themes (and Ubercart themes!) ~ Psst: more Ubercart themes on our new site

cfab's picture
Offline
Joined: 06/30/2009
Juice: 70
By "nested categories" what

By "nested categories" what I meant was the way taxonomy term images display by the category in the page, and you can drill down into each level.
Me too.

Are you talking about that or the subcategory navigation at the top?
About that.

Thanks for this interesting tutorial, but it's not dealing with the nested categories problem.

I've thought about Views Attach, maybe it's the solution here: I shall try and let you know.

The last module you cite sounds very promising!

stephthegeek's picture
Offline
Theminator
Joined: 10/20/2007
Juice: 575
Re: By "nested categories" what

You may also want to look at using the summary option in views with arguments. The default archive list view that comes with Views is an example of that. I've never used it with taxonomy but it combined with something related to term depth may be what you need. I wish I could be more specific, but I hope that helps.

Gorgeous original Drupal themes (and Ubercart themes!) ~ Psst: more Ubercart themes on our new site

loshuliveros's picture
Offline
Joined: 01/19/2011
Juice: 10
custom view of products in catalog

Hi all,
i had the same problem, i would like to use taxonomy terms like navigation in catalog module untouched, but i needed changing the presentation of products - i mean add some fields to generated table, but not only fields from uc_products table (for example i would like to add a teaser from node etc.).
It was first target and here is my solution:
All is about View module... After installation of Catalog module there is in Views a new view named "uc_products" with two standard "presets": Defaults and Page.
I found these two ways to achieve my first goal:

  1. You can configure "Page preset" - add new fields, disabling or deleting other fields etc., but you have to set the Arguments!!! In "Page preset" i've set "Taxonomy: Term ID" and detail i've kept unchanged. And final trick is to change Path for this view to the path which catalog use. If you didn't do any changes in "Automated alias settings" (admin/build/path/pathauto), default path is: catalog. Now you have your own presentation of product. But if one catalog term has a children - other catalog terms, the links to these children aren't shown in content space, because functions in catalog module aren't fired and all content is generated by View. It's not that, what i exactly need. It's time to the second way...
  2. This way is similar to the first one, but you should configure "Default preset" and in Arguments you have to set "Node: Nid" and in its detail check the option "Allow multiple terms per argument." Why "Node: Nid" and not "Taxonomy: Term ID". Because in my first way the argument comes from URL: for example in "www.mypage.com/catalog/5" the number 5 is Term ID of my currently clicked term (Catalog in block in left-sidebar). But in my second way i use a function "theme_uc_catalog_products" from file "uc_catalog.module". It's theme function, so hooking is very easy. Copy this function to your theme file template.php and rename it by your theme's name - if your theme's name is "dream", rename this function to "dream_uc_catalog_products" and make some changes:
    function dream_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 {
          //$table = tapir_get_table('uc_product_table', $products);
          //return drupal_render($table);
    foreach ($products as $key => $product_id) {
    if ((count($products) - 1) == $key) {
    $args .= $product_id;
    } else {
    $args .= $product_id . '+';
    }
    }
    return views_embed_view('uc_products', 'default', $args);
        }
      }

    Note i've disabled functions "tapir_get_table" and "drupal_render"! I've added a cycle, where argument $products (array with Node Nid's of products associated with currently clicked term) is transformed to string $args, because last used function "views_embed_view('uc_products', 'default', $args)" doesn't take as argument an array in this case - note detail of argument "Node: Nid" in Views->Default, where i've checked "Allow multiple terms per argument.". There is a help text: "If selected, users can enter multiple arguments in the form of 1+2+3 or 1,2,3.". I've read, that format "1+2+3" means logical "OR" and format "1,2,3" means logical "AND". That's why i've used sign "+" in construction of string $args.

OK, that's my first goal - solved. Can somebody test it?
PS: There in "dream_uc_catalog_products($products)" is second option for generating products as a grid. I think, you can use similar method to achieve a "dreamed" results...

My second goal was to achieve this:
Imagine you have catalog of terms like this:

  • A
    • aa
    • ab
    • ...
  • B
    • ba
    • bb
      • bba
      • ...
    • ...
  • ...

Root terms are "A", "B" etc. Second level terms (children of root terms) are "aa", "ab", "ba", ...
If my root term A hasn't any product, but it's children (in 2nd, 3th and so forth level) have some products, why when i click on term A, i'll see only links to the children? I would like to see all products from A to the deep of its tree and the links too, of course. In other words, children and its children are something like filters. If i'll click on deeper and deeper catalog term, i'd receive smaller and smaller collection of products.
If somebody would like to know, how to i've solved it, add a comment and than i'll write new article.
PS: I'm sorry for my english, it's not my native language...

qsilence's picture
Offline
Joined: 04/03/2011
Juice: 3
Multiselect

Just select also all parent categories for the product and you wil get the desired result without any further programming.

loshuliveros's picture
Offline
Joined: 01/19/2011
Juice: 10
Multiselect

I know, but number of nodes in taxonomy block (catalog) increases (+1), like there (in parent) is a new one product. Sorry for my english, but i mean, that is a little bit confusing - one product seems like it has one or more "instances" , if i have checked show number of nodes in catalog block...