Re: Mike, My site will use a

Posts: 88
Joined: 08/07/2007
Bug FinderGetting busy with the Ubercode.

Here is my current code. There are a few items I still need to work on.
1. Sorting products by the list order
2. Add a pager feature
3. Testing with other catalog structures besides mine. I currently have a Main Category(LEDs for the pro), Sub category(C6 Lights), and a product list page.

There are probably some other things that you will notice. I would like to break this into smaller theme sections, to make it easier to override a small section.

<?php
function holiday4_uc_catalog_browse($tid = 0){
 
drupal_add_css(drupal_get_path('module', 'uc_catalog') .'/uc_catalog.css');
 
//clear $output
 
$output = '';
  if (
$catalog->image){
   
$output .= theme('imagecache', 'thumbnail', $catalog->image['filepath'], $catalog->name, $catalog->name, array('class' => 'category'));
  }
 
//load the catalog
 
$catalog = uc_catalog_get_page($tid);
  if(
$catalog->name == 'Catalog') {
   
drupal_set_title('The LED Christmas Light Experts');
  }
  else {
   
drupal_set_title($catalog->name);
   
$output .= '<h1 class="uc_catalog_category_title">'.$catalog->name.'</h1>';
  }

 
$output .= $catalog->description;
 
$output .= '<div class="uc_catalog_clear_both"></div>';

 
drupal_set_breadcrumb(uc_catalog_set_breadcrumb($catalog->tid));

 
$types = array_keys(uc_product_node_info());
 
$links = array();
 
$child_list = array();

 
//Categories with subcategories(needs more logic)
 
$cat_val = 0;
  foreach(
$catalog->children as $category) {
    if(
$category->nodes >=1) {
      if(
$category->children != NULL) {
       
$output .= '<div class="uc_catalog_category '.(($cat_val % 2) ? 'uc_catalog_category_even' : 'uc_catalog_category_odd').'">'."\n";
       
$output .= '  <h2 class="uc_catalog_heading">'."\n";
       
$output .= '    '.l($category->name, taxonomy_term_path($category))."\n";
       
$output .= '  </h2>'."\n";
       
$output .= '  '.l( theme('imagecache', 'main_category', $category->image['filepath'], $category->name, $category->name, array('class' => 'uc_catalog_category_img')), taxonomy_term_path($category) , array(), NULL, NULL, FALSE, TRUE);
       
$output .= '  <div class="uc_catalog_main_catagory_description">'.$category->short_description.'</div>'."\n";

       
$sub_val = 0;
        foreach(
$category->children as $subcategory) {
         
$subcategory->image = db_fetch_array(db_query('SELECT f.filepath FROM term_node t INNER JOIN files f ON t.nid = f.nid WHERE f.filename NOT LIKE "" AND t.tid = %d LIMIT 1', $subcategory->tid));
          if(
$subcategory->image) {
            if(
$sub_val >=3) { break;}
           
$output .= '<div class="uc_catalog_subcategory '.(($sub_val % 2) ? 'uc_catalog_even' : 'uc_catalog_odd').'">'."\n";
           
$output .= '    '.l(theme('imagecache', 'thumbnail', $subcategory->image['filepath'], $subcategory->name, $subcategory->name, array('class' => 'uc_subcategory_img')), taxonomy_term_path($subcategory) , array(), NULL, NULL, FALSE, TRUE) ;
           
$output .= '  <div class="uc_catalog_subheading">'."\n";
           
$output .= '    '.l($subcategory->name, taxonomy_term_path($subcategory))."\n";
           
$output .= '  </div>'."\n";
           
$output .= '</div>'."\n";
           
$sub_val++;
          }
        }
       
$output .= '</div>'."\n";
       
$cat_val++;
      }
      else {
       
$output .= '<div class="'.(($cat_val % 2) ? 'uc_catalog_subcategory_even' : 'uc_catalog_subcategory_odd').'">'."\n";
       
$output .= '  <div class="uc_catalog_subcategory_link">'."\n";
       
$output .= '    '.l($category->name, taxonomy_term_path($category))."\n";
       
$output .= '  </div>'."\n";
       
$output .= '  '.l(theme('imagecache', 'sub_category', $category->image['filepath'], $category->name, $category->name, array('class' => 'uc_catalog_subcategory_img')), taxonomy_term_path($category), array(), NULL, NULL, FALSE, TRUE)."\n";
       
$output .= '  <div class="uc_catalog_subcategory_description">'."\n";
       
$output .= '    '.$category->short_description."\n";
       
$output .= '  </div>'."\n";
       
$output .= '  <div class="uc_catalog_teaser_more">'.l('more', taxonomy_term_path($category), array(), NULL, NULL, FALSE, TRUE).'</div>'."\n";
       
$output .= '</div>'."\n";
       
$cat_val++;
      }
    }
  }

 
$product_query = taxonomy_select_nodes(array($catalog->tid));
 
$val = 0;
 
$product_types = array_keys(uc_product_node_info());
  while(
$products = db_fetch_object($product_query)) {

    if(
$product = node_load($products->nid)) {
     
$stripe = ($val % 2) ? 'uc_catalog_even' : 'uc_catalog_odd';
     
$output .= '<div class="uc_category_product '.$stripe.'">'.node_view($product, TRUE).'</div>'."\n";
     
$val++;
    }
  }
  return
$output;
}
?>

Let me know what you think. I'd love to improve upon this.

Tableless catalog By: mikejoconnor (20 replies) Wed, 10/03/2007 - 08:04