#1538094: Drupal Commerce - number of items in the basket on a menu element discusses the altering of the cart menu link title provided by Commerce with various solutions proposed. It seems to me that this would be best handled using a theme function.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rattusrattus’s picture

Patch provides:

  • An additional declaration in commerce_cart_theme
  • theme_commerce_cart_menu_link_title() which returns the markup originally returned by commerce_cart_menu_item_title()
  • Modification of commerce_cart_menu_item_title() to use the new theme function

To use override theme_commerce_cart_menu_link_title in your template.php, e.g.:

function YOURTHEMENAME_commerce_cart_menu_link_title($vars) {
  $quantity = $vars['quantity'];
  return format_plural($quantity, 'My basket (1 item)', 'My basket (@count items)');
}
rattusrattus’s picture

Issue summary: View changes
rattusrattus’s picture

Issue summary: View changes
rattusrattus’s picture

Issue summary: View changes
rattusrattus’s picture

Patch without commeted out lines

rattusrattus’s picture

Whoops! missed the default title.

Updated example:

function YOURTHEMENAME_commerce_cart_menu_link_title($vars) {
  
  $quantity = $vars['quantity'];
  if ($quantity > 0) {
    $title = format_plural($quantity, 'My basket (1)', 'My basket (@count)');
  } else {
    $title = 'My basket';
  }
  
  return $title;
}

bverc’s picture

I really like this idea. I think it should be committed (yet to test).

Do you think it could be modified to allow it to be hidden when empty. (Not sure if setting to empty string is an elegant solution)
EDIT: On second thought, my problem might be too complex and best to implement entirely using THEME_menu_link()

calbasi’s picture

Not running for me... Please, if need more info to debug, just tell me...