public function removeItemFromCart($nid, $data) { $content = $this->getCartContents(); $product = node_load($nid); uc_product_load($product); if ($product->type == 'product_kit') { foreach ($data as $nid => $product) { uc_cart_remove_item($nid, uc_cart_get_id(), $product->data); } } else { uc_cart_remove_item($nid, uc_cart_get_id(), $data); } }
/** * Handle requests to update a cart item. * * @param $nid * Node id of the cart item. * @param $data * Array of extra information about the item. * @param $qty * The quantity of this item in the cart. * @param $cid * The cart id. Defaults to NULL, which indicates that the current user's cart * should be retrieved with uc_cart_get_id(). */ 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)); } // 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.')); } }
/** * Handles requests to update a cart item. * * @param $nid * Node id of the cart item. * @param $data * Array of extra information about the item. * @param $qty * The quantity of this item in the cart. * @param $cid * The cart id. Defaults to NULL, which indicates that the current user's cart * should be retrieved with uc_cart_get_id(). */ 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.')); } }