4 replies [Last post]
setfree's picture
Offline
Uber Donor
Joined: 12/16/2007
Juice: 436
Was this information Helpful?

On a standard product list generated from uc_product_table, is there any way to append field data to the 'name' field? My intent is to add sub-title and product dimension information under the 'name' and in the same table cell. I do not want to add cells to the table, but rather just add field data to the existing output.

Current example:

Image.....Name.............Price
img.......WidgetX..........$1
img.......WidgetY..........$2

Would like to output:

Image.....Name.............Price
img.......WidgetX..........$1
..........basic widget
..........2"x4"x6"
img.......WidgetY..........$2
..........Advanced Widget
..........4"x8"x6"

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3424
Re: Add fields to 'name' field in uc_product_table?

hook_table_alter()

<tr>.
setfree's picture
Offline
Uber Donor
Joined: 12/16/2007
Juice: 436
Re: Re: Add fields to 'name' field in uc_product_table?

Thanks for the reply. Yes, hook_table_alter is the hook I have been exploring. I have not yet found a way to write data back to an existing element though. Is it possible through this hook to take every product name, append new data to it, and then write this data back to the table?

Complete Computer Care

setfree's picture
Offline
Uber Donor
Joined: 12/16/2007
Juice: 436
Re: Re: Add fields to 'name' field in uc_product_table?

Never mind, I think I am on the right track now. I will post back with the complete solution when finished. Thanks Smiling

setfree's picture
Offline
Uber Donor
Joined: 12/16/2007
Juice: 436
Working code

This is the code I was able to use to get extra information appended to the product title in the product table.

<?php
// Appends subtitle and dimensions to uc_product_table
function mymodule_shipping_table_alter ($table_id, $op, $args) {
  if (
$table_id == 'uc_product_table') {
    switch (
$op) {
      case
'data':
        foreach (
$args['nids'] as $key => $nid) {
         
$n = db_fetch_array(db_query("SELECT title FROM {node} WHERE nid = %d",$nid));
         
// this is a CCK subtitle field attached to the product type. If a subtitle is entered then we want to display it in the table
         
$s = db_fetch_array(db_query("SELECT field_subtitle_value FROM {content_type_product} WHERE nid = %d",$nid));
         
$r = db_fetch_array(db_query("SELECT length,width,height FROM {uc_products} WHERE nid = %d",$nid));
            if (
$s['field_subtitle_value']) {$subtitle = '<br /><span class="subtitle">' . $s['field_subtitle_value'] . '</span>';}
         
// by query the table for the product title we lose the link so we must recreate it
         
$title = l($n['title'], drupal_get_path_alias('node/'. $nid));
         
$data['name'][] = $title . $subtitle . '<br /><span class="size">' . $r['length'] . '"L X ' . $r['width'] . '"W x' . $r['height'] . '"H</span>';
        }
     return
$data;
    }
  }
?>