function uc_restrict_qty_count in Ubercart Restrict Qty 6.2
Same name and namespace in other branches
- 5 uc_restrict_qty.module \uc_restrict_qty_count()
- 6 uc_restrict_qty.module \uc_restrict_qty_count()
- 7 uc_restrict_qty.module \uc_restrict_qty_count()
1 call to uc_restrict_qty_count()
- uc_restrict_qty_add_to_cart_data in ./
uc_restrict_qty.module - Implementation of hook_add_to_cart_data().
File
- ./
uc_restrict_qty.module, line 291 - 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_fetch_array(db_query("SELECT qty, lifetime FROM {uc_restrict_qty_products} WHERE nid = %d", $form_values['nid']));
if ($data['lifetime']) {
$bought_qty = db_result(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 = %d AND uop.nid = %d ORDER BY uop.nid', $user->uid, $form_values['nid']));
$data['rest'] = $data['qty'] - $bought_qty;
// Check what is currently in the users cart
$cart_products = uc_cart_get_contents($user->uid);
foreach ($cart_products as $product) {
if ($product->nid == $form_values['nid']) {
$data['rest'] -= $product->qty;
}
}
}
return $data;
}