You are here

function commerce_cart_menu_item_title in Commerce Core 7

Returns the title of the shopping cart menu item with an item count.

1 string reference to 'commerce_cart_menu_item_title'
commerce_cart_menu in modules/cart/commerce_cart.module
Implements hook_menu().

File

modules/cart/commerce_cart.module, line 73
Implements the shopping cart system and add to cart features.

Code

function commerce_cart_menu_item_title() {
  global $user;

  // Default to a static title.
  $title = t('Shopping cart');

  // If the user actually has a cart order...
  if ($order = commerce_cart_order_load($user->uid)) {

    // Count the number of product line items on the order.
    $wrapper = entity_metadata_wrapper('commerce_order', $order);
    $quantity = commerce_line_items_quantity($wrapper->commerce_line_items, commerce_product_line_item_types());

    // If there are more than 0 product line items on the order...
    if ($quantity > 0) {

      // Use the dynamic menu item title.
      $title = format_plural($quantity, 'Shopping cart (1 item)', 'Shopping cart (@count items)');
    }
  }
  return $title;
}