Skip navigation
Help

hook_uc_update_cart_item

7 uc_cart.api.php hook_uc_update_cart_item($nid, $data = array(), $qty, $cid = NULL)

Handles 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().

Related topics

2 functions implement hook_uc_update_cart_item()

2 invocations of hook_uc_update_cart_item()

File

ubercart/uc_cart/uc_cart.api.php, line 456
Hooks provided by the Cart module.

Code

function hook_uc_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_update('uc_cart_products')
      ->fields(array(
      'qty' => $qty, 
      'changed' => REQUEST_TIME,
    ))
      ->condition('nid', $nid)
      ->condition('cart_id', $cid)
      ->condition('data', serialize($data))
      ->execute();
  }

  // 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.'));
  }
}