What I want to do is have the special offers block display one product, randomly chosen. I've made some initial modifications below to put in my template.php file, and so far so good. First problem is, I know that "order by rand" is a terrible thing to put in SQL queries, but I have no idea how to do it the 'correct' way.
Second problem is that I don't want this product to display the add to cart button (which is designated in the tapir table for uc_catalog_products) - is there any way to add new tapir tables that I could then reference in this function for theming? Or alternatively a different an easy way to disable fields without changing the global tapir settings for that table?
Thanks in advance!
<?php
/**
* New Theme function for special offer products list
*/
function phptemplate_uc_marketing_special_products() {
$product_types = module_invoke_all('product_types');
$gridwidth = variable_get('uc_catalog_grid_display_width', 3);
if (variable_get('uc_catalog_grid_display', false)) {
$gridlines = variable_get('uc_marketing_special_block_lines', 1);
$gridwidth = $gridwidth * $gridlines;
}
$products = array();
$sql = "SELECT DISTINCT(n.nid), n.title, p.sell_price
FROM {node} n
INNER JOIN {uc_products} AS p ON n.nid = p.nid
WHERE n.status = 1
AND n.sticky = 1
AND n.type IN ('". implode("','", $product_types) ."')
ORDER BY RAND()";
$result = db_query_range($sql, 0, '1');
while ($node = db_fetch_object($result)) {
$products[] = $node->nid;
}
if (
count($products)) {
$output .= '<h2 class="title special">' . variable_get('uc_marketing_special_block_title', t('Special Offers')) . '</h2>';
$output .= theme('uc_catalog_products', $products);
if (variable_get('uc_marketing_special_block_help_allowed', true)) {
$output .= '<p class="special description">' . variable_get('uc_marketing_special_block_help', t("We're always looking for new ways to bring our products to the broadest audience. Here are our special offers for this month.")) . '</p>';
}
}
return $output;
}
?>

