Project:
UbercartCategory:
bug reportPriority:
criticalStatus:
by designWhen i use view to override product list on catalog page - it causes not to show category information - such as category description, image and subcategories links.
|
UbercartOne cart to rule them all... |
|
| Donate | Affiliates | Sponsors | ||
Using views to theme product list causes not to show category info
|
|
Re: Using views to theme product list causes not to show categor
That's happening because the features you're missing are features of the catalog module's display. Using a View overrides that altogether so that no part of the catalog module will be displayed. You would have to add these things in yourself or figure out something else to do.
Re: Re: Using views to theme product list causes not to show cat
So if i cant theme catalog list with views - how can i do it in another way?
Solve
I solve my problem in such way - i oveeride catalo page and insert view in it instead of standard ubercart product table. So now i can modify view - add columns, sort, filters for my product list in catalog.
Just put this code in my template.php
<?php
/**
* Display a formatted catalog page.
*
* If the category has products in it, display them in a TAPIr table. Subcategories
* are linked along the top of the page. If it does not have products, display
* subcategories in a grid with their images and subcategories.
*
* @param $tid
* Catalog term id from URL.
* @return
* Formatted HTML of the catalog page.
*/
function phptemplate_uc_catalog_browse($tid = 0) {
drupal_add_css(drupal_get_path('module', 'uc_catalog') .'/uc_catalog.css');
$output = '';
$catalog = uc_catalog_get_page((int)$tid);
drupal_set_title(check_plain($catalog->name));
drupal_set_breadcrumb(uc_catalog_set_breadcrumb($catalog->tid));
$types = module_invoke_all('product_types');
$links = array();
$child_list = array();
foreach ($catalog->children as $child) {
if ($child->nodes) {
$links[] = array('title' => $child->name . (variable_get('uc_catalog_breadcrumb_nodecount', false) ? ' ('. $child->nodes .')' : ''), 'href' => uc_catalog_path($child),
'attributes' => array('rel' => 'tag'),
);
}
if ($child->image) {
$image = '<div>';
if (module_exists('imagecache')) {
$image .= l(theme('imagecache', 'category', $child->image['filepath']), uc_catalog_path($child), array(), null, null, false, true);
}
else {
$image.= l(theme('image', $child->image['filepath']), uc_catalog_path($child), array(), null, null, false, true);
}
$image .= '</div>';
}
else {
$image = '<div></div>';
}
$grandchildren = array();
$j = 0;
$max_gc_display = 3;
foreach ($child->children as $i => $grandchild) {
if ($j > $max_gc_display) {
break;
}
$g_child_nodes = 0;
foreach ($types as $type) {
$g_child_nodes += taxonomy_term_count_nodes($grandchild->tid, $type);
}
if ($g_child_nodes) {
$grandchildren[$i] = l($grandchild->name, uc_catalog_path($grandchild), array('class' => 'subcategory'));
$j++;
}
}
//$grandchildren = array_slice($grandchildren, 0, intval(count($grandchildren) / 2) + 1, true);
if ($j > $max_gc_display) {
array_push($grandchildren, l(t('More...'), uc_catalog_path($child), array('class' => 'subcategory')));
}
if ($child->nodes) {
$cell_link = $image .'<strong>'. l($child->name, uc_catalog_path($child)) .'</strong>';
if (variable_get('uc_catalog_show_subcategories', true)) {
$cell_link .= "<br/><span>". implode(', ', $grandchildren) ."</span>\n";
}
$child_list[] = $cell_link;
}
}
// Display table of child categories similar to an osCommerce site's front page.
$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' => ' ', 'class' => 'category')));
}
$cat_rows[] = $row;
}
/*inserting product view*/
if ($tid != 0) {
$view_name = 'products'; //!!! ---> name of view whic holds product with a Trem ID as an argument
$view_args = array($tid);
$view = views_get_view($view_name);
$view->url = $_GET['q'];
$catalog->products = views_build_view('embed', $view, $view_args, $view->use_pager, $view->nodes_per_page);
} else {
$catalog->products = '';
}
if ($catalog->products) {
if ($catalog->image) {
$output .= '<div class="uc-catalog-image">'. theme('imagecache', 'thumbnail', $catalog->image['filepath'], $catalog->name, $catalog->name, array('class' => 'category')) .'</div>';
}
if ($catalog->description) {
$output .= '<div class="uc-catalog-description">'. $catalog->description .'</div>';
}
$output .= theme('table', array(), $cat_rows, array('class' => 'category'));
$output .= $catalog->products;
} else {
if ($catalog->image && $catalog->description) {
$output .= '<div class="uc-catalog-image">'. theme('imagecache', 'thumbnail', $catalog->image['filepath'], $catalog->name, $catalog->name, array('class' => 'category')) .'</div>';
$output .= '<div class="uc-catalog-description">'. $catalog->description .'</div>';
}
$output .= theme('table', array(), $cat_rows, array('class' => 'category'));
}
return $output;
}
?>
Pay attention to the name of View which is inserted in catalog page = You must specify your own view name
Re: Using views to theme product list causes not to show categor
eugef's template code is very handy.
However, just a little pointer: The imagecache names in the code are different from that used in Ubercart 5x-1.5. So if you are using the code, the images wont appear correctly.
e.g. UC_Category is renamed to "category" in the code, so if there isn't a "category" preset on your website, the image wont appear.
The solution is to rename "category" and "thumbnail" in the code to uc_category and uc_thumbnail.
Another solution is to create new imagecache presets called category and thumbnail.
^_^
Re: Re: Using views to theme product list causes not to show cat
This works great for me too except one thing....
When I put this code in my template.php file I do get my updated catalog view but anytime I make an edit on the site i get a white screen. For example if i create a new blog post i get a white screen but the post does show up if i go to the homepage and find it.
I would appreciate any ideas on how to fix this.