function uc_restrict_qty_count in Ubercart Restrict Qty 7
Same name and namespace in other branches
- 5 uc_restrict_qty.module \uc_restrict_qty_count()
- 6.2 uc_restrict_qty.module \uc_restrict_qty_count()
- 6 uc_restrict_qty.module \uc_restrict_qty_count()
Returns the number of restrict_qty features on a product node.
1 call to uc_restrict_qty_count()
- uc_restrict_qty_uc_add_to_cart_data in ./
uc_restrict_qty.module - Implements hook_add_to_cart_data().
File
- ./
uc_restrict_qty.module, line 313 - Restrict the quantity on specified products so that only specified quantity may be purchased at a time.
Code
function uc_restrict_qty_count($form_values) {
global $user;
$data = db_query("SELECT qty, lifetime FROM {uc_restrict_qty_products} WHERE nid = :nid", array(
':nid' => $form_values['nid'],
))
->fetchAssoc();
if ($data['lifetime']) {
$bought_qty = db_query('SELECT SUM(uop.qty) FROM {uc_orders} uo LEFT JOIN {uc_order_products} uop ON uo.order_id = uop.order_id WHERE uo.order_status = :completed AND uo.uid = :uid AND uop.nid = :nid ORDER BY uop.nid', array(
':completed' => 'completed',
':uid' => $user->uid,
':nid' => $form_values['nid'],
))
->fetchField();
$data['rest'] = $data['qty'] - $bought_qty;
}
return $data;
}