You are here

function hook_update_cart_item in Ubercart 5

Same name and namespace in other branches
  1. 6.2 docs/hooks.php \hook_update_cart_item()

Handle requests to update a cart item.

Parameters

$nid: Node id of the cart item.

$data: Array of extra information about the item.

$qty: The quantity of this item in the cart.

$cid: The cart id. Defaults to NULL, which indicates that the current user's cart should be retrieved with uc_cart_get_id().

3 functions implement hook_update_cart_item()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

uc_product_kit_update_cart_item in uc_product_kit/uc_product_kit.module
Implementation of Übercart's hook_update_cart_item().
uc_product_update_cart_item in uc_product/uc_product.module
Update information about a specific item in current cart.
uc_quote_update_cart_item in shipping/uc_quote/uc_quote.module
2 invocations of hook_update_cart_item()
uc_cart_add_item in uc_cart/uc_cart.module
Adds an item to a user's cart.
uc_cart_update_item_object in uc_cart/uc_cart.module
Updates the quantity of all the items in a cart object

File

docs/hooks.php, line 1096
These are the hooks that are invoked by the Übercart core.

Code

function hook_update_cart_item($nid, $data = array(), $qty, $cid = NULL) {
  if (!$nid) {
    return NULL;
  }
  $cid = !(is_null($cid) || empty($cid)) ? $cid : uc_cart_get_id();
  if ($qty < 1) {
    uc_cart_remove_item($nid, $cid, $data);
  }
  else {
    db_query("UPDATE {uc_cart_products} SET qty = %d, changed = %d WHERE nid = %d AND cart_id = '%s' AND data = '%s'", $qty, time(), $nid, $cid, serialize($data));
    cache_clear_all();
  }

  // Rebuild the items hash
  uc_cart_get_contents(NULL, 'rebuild');
  if (!strpos(request_uri(), 'cart', -4)) {
    drupal_set_message(t('Your item(s) have been updated.'));
  }
}