function uc_order_update_6012 in Ubercart 6.2
Populate the total product quantity.
File
- uc_order/
uc_order.install, line 889 - Install, update and uninstall functions for the uc_order module.
Code
function uc_order_update_6012(&$sandbox) {
$ret = array();
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['current_order_id'] = 0;
$sandbox['max'] = db_result(db_query("SELECT COUNT(DISTINCT order_id) FROM {uc_order_products} WHERE order_id <> 0"));
}
$limit = 100;
$result = db_query_range("SELECT order_id, SUM(qty) AS product_count FROM {uc_order_products} WHERE order_id > %d GROUP BY order_id", $sandbox['current_order_id'], 0, $limit);
while ($row = db_fetch_object($result)) {
db_query("UPDATE {uc_orders} SET product_count = %d WHERE order_id = %d", $row->product_count, $row->order_id);
$sandbox['progress']++;
$sandbox['current_order_id'] = $row->order_id;
}
$ret['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
if ($ret['#finished'] == 1) {
$t = get_t();
$ret[] = array(
'success' => TRUE,
'query' => $t("Populated the product count column for {uc_orders}."),
);
}
return $ret;
}