You are here

function hook_cart_display in Ubercart 6.2

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

Controls the display of an item in the cart.

Product type modules allow the creation of nodes that can be added to the cart. The cart determines how they are displayed through this hook. This is especially important for product kits, because it may be displayed as a single unit in the cart even though it is represented as several items.

This hook is only called for the module that owns the cart item in question, as set in $item->module.

Parameters

$item: The item in the cart to display.

Return value

A form array containing the following elements:

  • "nid"

    • #type: value
    • #value: The node id of the $item.
  • "module"
    • #type: value
    • #value: The module implementing this hook and the node represented by $item.
  • "remove"
    • #type: submit
    • #value: t('Remove'); when clicked, will remove $item from the cart.
  • "description"
    • #type: markup
    • #value: Themed markup (usually an unordered list) displaying extra information.
  • "title"
    • #type: markup
    • #value: The displayed title of the $item.
  • "#total"
    • "type": float
    • "value": Numeric price of $item. Notice the '#' signifying that this is not a form element but just a value stored in the form array.
  • "data"
    • #type: hidden
    • #value: The serialized $item->data.
  • "qty"
    • #type: textfield
    • #value: The quantity of $item in the cart. When "Update cart" is clicked, the customer's input is saved to the cart.
2 functions implement hook_cart_display()

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

uc_product_cart_display in uc_product/uc_product.module
Implements hook_cart_display().
uc_product_kit_cart_display in uc_product_kit/uc_product_kit.module
Implements hook_cart_display().
3 invocations of hook_cart_display()
uc_cart_block in uc_cart/uc_cart.module
Implements hook_block().
uc_cart_checkout in uc_cart/uc_cart.pages.inc
Displays the cart checkout page built of checkout panes from enabled modules.
uc_cart_view_form in uc_cart/uc_cart.module
Displays a page allowing the customer to view the contents of his or her cart.

File

docs/hooks.php, line 208
These are the hooks that are invoked by the Ubercart core.

Code

function hook_cart_display($item) {
  $node = node_load($item->nid);
  $element = array();
  $element['nid'] = array(
    '#type' => 'value',
    '#value' => $node->nid,
  );
  $element['module'] = array(
    '#type' => 'value',
    '#value' => 'uc_product',
  );
  $element['remove'] = array(
    '#type' => 'checkbox',
  );
  $element['title'] = array(
    '#value' => node_access('view', $node) ? l($item->title, 'node/' . $node->nid) : check_plain($item->title),
  );
  $context = array(
    'revision' => 'altered',
    'type' => 'cart_item',
    'subject' => array(
      'cart_item' => $item,
      'node' => $node,
    ),
  );
  $price_info = array(
    'price' => $item->price,
    'qty' => $item->qty,
  );
  $element['#total'] = uc_price($price_info, $context);
  $element['data'] = array(
    '#type' => 'hidden',
    '#value' => serialize($item->data),
  );
  $element['qty'] = array(
    '#type' => 'textfield',
    '#default_value' => $item->qty,
    '#size' => 5,
    '#maxlength' => 6,
  );
  if ($description = uc_product_get_description($item)) {
    $element['description'] = array(
      '#value' => $description,
    );
  }
  return $element;
}