Last updated March 1, 2012. Created on February 10, 2012.
Edited by fonant. Log in to edit this page.

Here's a snippet to filter Ubercart products that are "On Sale" - that is, where the Sell price is less than the List price.

(The 0.005 (half a penny if GBP currency) is included because sometimes the VAT module rounds the prices so a price of £10.42 can appear in the database as 10.41667.)

<?php
$node_ids
= array();

// Find current node revisions that are on sale.
$sql = "SELECT n.nid FROM {node} n
JOIN {uc_products} p ON n.vid = p.vid
WHERE p.sell_price < p.list_price - 0.005"
;

// Rewrite query to apply node access rules
$sql = db_rewrite_sql($sql);

// Run query.
$result = db_query($sql);

// Get list of NIDs.
while ($row = db_fetch_array($result)) {
 
$node_ids[] = $row['nid'];
}

return
$node_ids;
?>

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.