Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Implements hook_menu().
- */
- function commerce_cart_menu() {
- $items = array();
- $items['cart'] = array(
- 'title' => 'Shopping cart',
- 'page callback' => 'commerce_cart_view',
- 'access arguments' => array('access content'),
- 'file' => 'includes/commerce_cart.pages.inc',
- );
- $items['cart/my'] = array(
- 'title' => 'Shopping cart (# items)',
- 'title callback' => 'commerce_cart_menu_item_title',
- 'title arguments' => array(TRUE),
- 'page callback' => 'commerce_cart_menu_item_redirect',
- 'access arguments' => array('access content'),
- 'type' => MENU_SUGGESTED_ITEM,
- );
- $items['checkout'] = array(
- 'title' => 'Checkout',
- 'page callback' => 'commerce_cart_checkout_router',
- 'access arguments' => array('access checkout'),
- 'type' => MENU_CALLBACK,
- 'file' => 'includes/commerce_cart.pages.inc',
- );
- // If the Order UI module is installed, add a local action to it that lets an
- // administrator execute a cart order refresh on the order. Modules that
- // define their own order edit menu item are also responsible for defining
- // their own local action menu items if needed.
- if (module_exists('commerce_order_ui')) {
- $items['admin/commerce/orders/%commerce_order/edit/refresh'] = array(
- 'title' => 'Apply pricing rules',
- 'description' => 'Executes the cart order refresh used to apply all current pricing rules on the front end.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('commerce_cart_order_refresh_form', 3),
- 'access callback' => 'commerce_cart_order_refresh_form_access',
- 'access arguments' => array(3),
- 'type' => MENU_LOCAL_ACTION,
- 'file' => 'includes/commerce_cart.admin.inc',
- );
- }
- return $items;
- }
- /**
- * Returns the title of the shopping cart menu item with an item count.
- */
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement