Zen Follower
- Join Date:
- Aug 2006
- Posts:
- 136
- Plugin Contributions:
- 0
zen_products_lookup: How do I "return any field"?
I found the code below in functions_lookup.php. Methinks I should be able to use it to great advantage to pass any field from the products or products_description tables to a module or tpl file. But how? is the question, yes!
/*
* Return any field from products or products_description table
* Example: zen_products_lookup('3', 'products_date_added');
*/
function zen_products_lookup($product_id, $what_field = 'products_name', $language = '') {
global $db;
if (empty($language)) $language = $_SESSION['languages_id'];
$product_lookup = $db->Execute("select " . $what_field . " as lookup_field
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
where p.products_id ='" . (int)$product_id . "'
and pd.language_id = '" . (int)$language . "'");
$return_field = $product_lookup->fields['lookup_field'];
return $return_field;
}
Let's say for a link's text I wanted to pass products_model to the also_purchased_products.php module instead of or in addition to passing the products_name. I tried substituting zen_products_lookup($product['id'], 'products_model') for $also_purchased_products->fields['products_name'] (see detail below) but that did not work. I looked at the various threads like How Do I Add the Model Number to My Cart? threads and found the inline method for templates but I'm having trouble translating this code to module use.
What am I doing wrong?
'text' => (($also_purchased_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '<a href="' . zen_href_link(zen_get_info_page($also_purchased_products->fields['products_id']), 'products_id=' . $also_purchased_products->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $also_purchased_products->fields['products_image'], $also_purchased_products->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br />') . '<a href="' . zen_href_link(zen_get_info_page($also_purchased_products->fields['products_id']), 'products_id=' . $also_purchased_products->fields['products_id']) . '">' . zen_products_lookup($product['id'], 'products_model') . '</a>');