You are here

function uc_restrict_qty_cart_item in Ubercart Restrict Qty 6

Same name and namespace in other branches
  1. 5 uc_restrict_qty.module \uc_restrict_qty_cart_item()
  2. 6.2 uc_restrict_qty.module \uc_restrict_qty_cart_item()

Implementation of hook_cart_item().

File

./uc_restrict_qty.module, line 115
Restrict the quantity on specified products so that only one may be purchased at a time.

Code

function uc_restrict_qty_cart_item($op, &$item) {
  if ($op == 'load') {

    // If this item has a quantity restriction on it...
    if ($item->data['restrict_qty'] > 0 && $item->qty > 1) {

      // Reduce the quantity to 1 if necessary.
      db_query("UPDATE {uc_cart_products} SET qty = 1, changed = %d WHERE cart_id = '%s' AND nid = %d AND data = '%s'", time(), uc_cart_get_id(), $item->nid, serialize($item->data));
      $item->qty = 1;
    }
  }
}