expanding link blocks to show links to products under categories? (Attn: Lyle)

Posts: 4
Joined: 06/02/2008

i've rephrased this question so that it is more clear:

in the catalog link block, is there currently a way to make categories or subcategories expand to show the products within them (and links to the actual product pages). or is there any way to get links directly to product pages (instead of category pages) into any link block?

i apologize in advance for my noobishness. thanks!

Posts: 4
Joined: 06/02/2008

I looked deeper into this and found that this is not currently supported by ubercart.
So, i decided to take on the project myself. I have it working roughly and would like to make this into an official option for the module, however, i'll need a bit of assistance to fully pull it off.

I'm working with the uc_catalog.module

Basically what I did to get this functionality going in a very very crude way is this:
I created a function called get_page_links like this:

<?php
/***********************************************
* GET Links of Pages within a specific Category
************************************************/

function get_page_links($tid = 0) {

 
$output = '';
 
$catalog = uc_catalog_get_page((int)$tid);

 
$types = module_invoke_all('product_types');
 
$links = array();

 
$order = 'p.ordering, n.title, n.nid';
 
$product_types = module_invoke_all('product_types');

 
$sql = "SELECT DISTINCT(n.nid), n.sticky, n.title, n.created, p.model, p.ordering
    FROM {node} n
      INNER JOIN {term_node} tn ON n.nid = tn.nid
      INNER JOIN {uc_products} AS p ON n.vid = p.vid
    WHERE tn.tid = %d AND n.status = 1
      AND n.type IN ('"
. implode("','", $product_types) ."')
    ORDER BY "
. $order;
 
$sql_count = '';
  switch (
$GLOBALS['db_type']) {
    case
'mysql':
    case
'mysqli':
     
$sql_count = 'SELECT COUNT(DISTINCT(n.nid))
        FROM {node} n
          INNER JOIN {term_node} tn ON n.nid = tn.nid
          INNER JOIN {uc_products} AS p ON n.nid = p.nid
        WHERE tn.tid = %d
          AND n.status = 1
          AND n.type IN ("'
. implode('","', $product_types) .'")';
      break;
    case
'pgsql':
     
$sql_count = "SELECT DISTINCT n.nid, COUNT(*)
        FROM {node} n
          INNER JOIN {term_node} tn ON n.nid = tn.nid
          INNER JOIN {uc_products} AS p ON n.nid = p.nid
        WHERE tn.tid = %d
          AND n.status = 1
          AND n.type IN ('"
. implode("','", $product_types) ."')
        GROUP BY n.nid"
;
      break;
  }

 
$sql = db_rewrite_sql($sql);
 
$sql_count = db_rewrite_sql($sql_count);
 
$catalog->products = array();
 
$result = pager_query($sql, variable_get('uc_product_nodes_per_page', 12), 0, $sql_count, $catalog->tid);

  while (
$node = db_fetch_object($result)) {
   
$catalog->products[] = $node->nid;
  }

 
$product_links = array();
  if (
count($catalog->products)) {
    foreach (
$catalog->products as $nid) {
   
$product = node_load($nid);
   
$titlelink = l($product->title, "node/$nid", array(), null, null, false, true);
   
$product_links[] = $titlelink;
    }
  }

  return
$product_links;
}
?>

Next, I added a few lines of code to the _uc_catalog_navigation function:
<?php
 
if($branch->tid == 1) {
   
$lis = get_page_links($branch->tid);
  }
?>

Just before this line of code:
<?php
  $output
= theme("uc_catalog_item", $here, $active_link, $lis, $expand, $inpath, $link, count($branch->children));
?>

Basically, I'd like to make this functionality rolled into the module as an option.
Currently, I have it branching out all products under category 1 (as shown by $branch->tid == 1).
I'd like to be able to make it so that the user can choose which category(s) they want to have product links listed under (instead of all categories).
This was my first shot at modifying any drupal modules so I'm not sure where to go from here, and I'm asking for some assistance.

Why do I think this is a necessary feature?
This feature is necessary for small store owners with less than 50 products under a single category.
The search engine optimization benefits are enormous. Instead of distributing the pages' pagerank among category pages (which would be full of nothing but a single product), all of the pagerank is being distributed directly to the product pages (making it easier for consumers to find your product pages in the search engines). Furthermore, every product on the site is then linking to every other product on the site, which is awesome for internal optimization for those niche keywords/products you're targeting.

So, if you'd like to help me make this into a feature of the module, let me know! Its a feature I haven't seen in any other shopping cart systems yet, and I believe it is a truly necessary feature for small store owners.