You are here

function hook_cart_item in Ubercart 5

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

Add extra data about an item in the cart.

Products that are added to a customer's cart are referred as items until the sale is completed. Just think of a grocery store having a bunch of products on the shelves but putting a sign over the express lane saying "15 Items or Less." hook_cart_item() is in charge of acting on items at various times like when they are being added to a cart, saved, loaded, and checked out.

Here's the rationale for this hook: Products may change on a live site during a price increase or change to attribute adjustments. If a user has previously added an item to their cart, when they go to checkout or view their cart screen we want the latest pricing and model numbers to show. So, the essential product information is stored in the cart, but when the items in a cart are loaded, modules are given a chance to adjust the data against the latest settings.

Parameters

$op: The action that is occurring. Possible values:

  • "load" - Passed for each item when a cart is being loaded in the function uc_cart_get_contents(). This gives modules the chance to tweak information for items when the cart is being loaded prior to being view or added to an order. No return value is expected.
  • "can_ship" - Passed when a cart is being scanned for items that are not shippable items. Übercart will bypass cart and checkout operations specifically related to tangible products if nothing in the cart is shippable. hook_cart_item functions that check for this op are expected to return TRUE or FALSE based on whether a product is shippable or not.

Return value

No return value for load. TRUE or FALSE for can_ship.

7 functions implement hook_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_attribute_cart_item in uc_attribute/uc_attribute.module
Implementation of hook_cart_item().
uc_file_cart_item in uc_file/uc_file.module
Implementation of hook_cart_item().
uc_product_kit_cart_item in uc_product_kit/uc_product_kit.module
Implementation of Übercart's hook_cart_item().
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.

... See full list

3 invocations of hook_cart_item()
uc_cart_get_contents in uc_cart/uc_cart.module
Grab the items in a shopping cart for a user.
uc_cart_product_is_shippable in uc_cart/uc_cart.module
uc_order_is_shippable in uc_order/uc_order.module

File

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

Code

function hook_cart_item($op, &$item) {
  switch ($op) {
    case 'load':
      $term = array_shift(taxonomy_node_get_terms_by_vocabulary($item->nid, variable_get('uc_manufacturer_vid', 0)));
      $arg1->manufacturer = $term->name;
      break;
  }
}