function hook_uc_update_cart_item in Ubercart 8.4
Same name and namespace in other branches
- 7.3 uc_cart/uc_cart.api.php \hook_uc_update_cart_item()
Handles requests to update a cart item.
Parameters
int $nid: Node id of the cart item.
array $data: Array of extra information about the item.
int $qty: The quantity of this item in the cart.
int $cid: The cart id. Defaults to NULL, which indicates that the current user's cart should be retrieved with uc_cart_get_id().
2 functions implement hook_uc_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_uc_update_cart_item in uc_product_kit/
uc_product_kit.module - Implements hook_uc_update_cart_item().
- uc_product_uc_update_cart_item in uc_product/
uc_product.module - Implements hook_uc_update_cart_item().
2 invocations of hook_uc_update_cart_item()
- Cart::addItem in uc_cart/
src/ Cart.php - Adds an item to the cart.
- CartForm::submitForm in uc_cart/
src/ Form/ CartForm.php - Form submission handler.
File
- uc_cart/
uc_cart.api.php, line 276 - Hooks provided by the Cart module.
Code
function hook_uc_update_cart_item($nid, array $data = [], $qty, $cid = NULL) {
$cid = !(is_null($cid) || empty($cid)) ? $cid : uc_cart_get_id();
$result = \Drupal::entityQuery('uc_cart_item')
->condition('cart_id', $cid)
->condition('nid', $nid)
->condition('data', serialize($data))
->execute();
if (!empty($result)) {
$item = \Drupal\uc_cart\Entity\CartItem::load(current(array_keys($result)));
if ($item->qty->value != $qty) {
$item->qty->value = $qty;
$item
->save();
}
}
}