Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. /**
  2. * Implements hook_menu().
  3. */
  4. function commerce_cart_menu() {
  5. $items = array();
  6.  
  7. $items['cart'] = array(
  8. 'title' => 'Shopping cart',
  9. 'page callback' => 'commerce_cart_view',
  10. 'access arguments' => array('access content'),
  11. 'file' => 'includes/commerce_cart.pages.inc',
  12. );
  13.  
  14. $items['cart/my'] = array(
  15. 'title' => 'Shopping cart (# items)',
  16. 'title callback' => 'commerce_cart_menu_item_title',
  17. 'title arguments' => array(TRUE),
  18. 'page callback' => 'commerce_cart_menu_item_redirect',
  19. 'access arguments' => array('access content'),
  20. 'type' => MENU_SUGGESTED_ITEM,
  21. );
  22.  
  23. $items['checkout'] = array(
  24. 'title' => 'Checkout',
  25. 'page callback' => 'commerce_cart_checkout_router',
  26. 'access arguments' => array('access checkout'),
  27. 'type' => MENU_CALLBACK,
  28. 'file' => 'includes/commerce_cart.pages.inc',
  29. );
  30.  
  31. // If the Order UI module is installed, add a local action to it that lets an
  32. // administrator execute a cart order refresh on the order. Modules that
  33. // define their own order edit menu item are also responsible for defining
  34. // their own local action menu items if needed.
  35. if (module_exists('commerce_order_ui')) {
  36. $items['admin/commerce/orders/%commerce_order/edit/refresh'] = array(
  37. 'title' => 'Apply pricing rules',
  38. 'description' => 'Executes the cart order refresh used to apply all current pricing rules on the front end.',
  39. 'page callback' => 'drupal_get_form',
  40. 'page arguments' => array('commerce_cart_order_refresh_form', 3),
  41. 'access callback' => 'commerce_cart_order_refresh_form_access',
  42. 'access arguments' => array(3),
  43. 'type' => MENU_LOCAL_ACTION,
  44. 'file' => 'includes/commerce_cart.admin.inc',
  45. );
  46. }
  47.  
  48. return $items;
  49. }
  50.  
  51. /**
  52. * Returns the title of the shopping cart menu item with an item count.
  53. */
  54. function commerce_cart_menu_item_title() {
  55. global $user;
  56.  
  57. // Default to a static title.
  58. $title = t('Shopping cart');
  59.  
  60. // If the user actually has a cart order...
  61. if ($order = commerce_cart_order_load($user->uid)) {
  62. // Count the number of product line items on the order.
  63. $wrapper = entity_metadata_wrapper('commerce_order', $order);
  64. $quantity = commerce_line_items_quantity($wrapper->commerce_line_items, commerce_product_line_item_types());
  65.  
  66. // If there are more than 0 product line items on the order...
  67. if ($quantity > 0) {
  68. // Use the dynamic menu item title.
  69. $title = format_plural($quantity, 'Shopping cart (1 item)', 'Shopping cart (@count items)');
  70. }
  71. }
  72.  
  73. return $title;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement