Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Drupalien Hello!
I hit a small problem with my drupal trade!
I created a menu with the API of drupal, the items are "registration" "connection" "Shopping Cart".
My goal is to add the number of items in basket a side of the menu title "Shopping Cart" to have made this (3) Shopping Cart.
Someone has a track or a specific method please?
Thank you all.
Comments
Comment #1
rszrama CreditAttribution: rszrama commentedThere's already a menu item for this in the Cart module, you just need to enable it. : )
Comment #2
woprrr CreditAttribution: woprrr commentedOh! seriously?! ca or I can not find?!
Comment #3
woprrr CreditAttribution: woprrr commentedComment #4
rszrama CreditAttribution: rszrama commentedIt's a disabled link in your Navigation menu. You'll see it; just need to enable it.
Comment #5
woprrr CreditAttribution: woprrr commentedOH MY GOD I don't look this >_< ! thanks and sorry ;)
Comment #6
rszrama CreditAttribution: rszrama commentedlol No worries. It's kinda hidden away in there. : P
Comment #8
Anonymous (not verified) CreditAttribution: Anonymous commentedI don't think this is fixed because the op said they wanted to display it like this: (3) Shopping Cart. But if I try and change anything about the menu item text, the number stops showing up - instead it just shows a # character. I guess this is because the Commerce Cart module is doing a replace on the full string "Shopping cart (# items)" - would it be possible to change it so that it just replaces the '#' no matter what the rest of the string is? I would like to have Basket (3).
Comment #9
rszrama CreditAttribution: rszrama commentedWhat you'll need to do is either 1) override the title callback of the menu item and copy / modify the callback from the Cart module as necessary or 2) perhaps you can translate the strings 'Shopping cart (1 item)' and 'Shopping cart (@count items)' to achieve your desired result.
Comment #10
woprrr CreditAttribution: woprrr commentedThe two numbers works well!
Comment #11
2phaI wanted it in the format of 'cart (1)' and did it with the string override module
http://drupal.org/project/stringoverrides/
Comment #12
germaike mv CreditAttribution: germaike mv commentedComment #13
woprrr CreditAttribution: woprrr commentedAnother technique is to also create a view, which allows many possibilities!
Comment #14
nigelw CreditAttribution: nigelw commentedGoing to reopen as I am trying to achieve this with string overrides using just settings.php (as I don't want to install another module just to do this). It appears using any of the following has no affect. Thoughts?
Comment #15
rszrama CreditAttribution: rszrama commentedYou sure you have the array syntax right? I'm not sure you should have a NULL string in there as an array key.
Comment #16
nigelw CreditAttribution: nigelw commentedAll I am doing is modifying the examples to fit this scenario. Am I missing something. I need some hand holding :(
Comment #17
rszrama CreditAttribution: rszrama commentedSorry, then I'm not sure. Unfortunately, we don't provide multilingual support here in the issue queue. Maybe it's something as simple as not having the Locale module enabled or something else, but there's nothing here specific to Drupal Commerce. I'd recommend finding Drupal translation tutorials or something.
Comment #18
rajeevkHello,
How it can be done by stringoverride module ?
I tried like 'Shopping cart (@count items)' to 'Cart (@count)' , but it didn't work.
Thanks :)
Comment #19
remydenton CreditAttribution: remydenton commentedI went the route of doing a custom menu item callback. Here's some sample code in case it's helpful to anyone (just adapt the text in the second function to your specific needs; using it as-is will change "Shopping Cart" to "My Cart"):
Comment #20
rajeevk@remydenton - Worked like charm. Thanks for it...
Comment #21
devonuto CreditAttribution: devonuto commentedWhat would be the best way to hide the link altogether if the cart is empty via this method?
Comment #22
woprrr CreditAttribution: woprrr commentedWith this method set $title = NULL; work for me ;)
It's actualy best method to views your cart (it's superpower with custom panel blocks).
Comment #23
zendric CreditAttribution: zendric commentedThanks for this one Remy!
But I'm a bit stuck here... I'm trying to get the menu item to show just the number of different products in cart, not the total quantity of all the items. Is it possible with this same approach?
Comment #24
zendric CreditAttribution: zendric commentedComment #25
rszrama CreditAttribution: rszrama commentedYep, you can do the same thing - just take out the bits that actually put the "My cart" text in there. Let's leave this issue closed, though, as it's quite old and we've since moved to using the Commerce Q&A on DC.org. You could also just not use this at all and translate the strings instead, since format_plural() arguments should be translatable.
Comment #26
jenlamptonI would like to re-open this issue as a feature request. I have the same thought as in #8 that the module should only be replacing the # in the string provided in the menu UI. I actually went to the menu UI and changed the string several times before I realized this was not already happening.
Is there a way we can read in what's provided in the UI, and use that as the singular string for format_plural, simply replacing the # with @count?
Comment #27
RedEight CreditAttribution: RedEight commentedThe solution in #1538094-19: Drupal Commerce - number of items in the basket on a menu element appears to work when I dropped it into my theme module. However, it occasionally falls back to the one title from the cart module.
Kind of maddening actually... Cache clearing can cause it to switch which one is handling it but there doesn't seem to be a rhyme or reason to it.
Comment #28
nadavoid CreditAttribution: nadavoid commentedIf using a menu item added manually in the menu UI, using
hook_menu_alter()
will not affect the link title. In that case,hook_preprocess_link()
will work.Comment #29
nithinkolekar CreditAttribution: nithinkolekar commentedfor future readers..
with the code provided @ #19 menu item not get updated when cart modified(cache has to flushed every time).
Comment #30
O U T L A W CreditAttribution: O U T L A W commentedI don't know if it is right implement this kind of logic in a theme function, but it works for me and I'm able to edit the link text in the Drupal UI. This code works for all links, you can use theme_menu_link() to alter only menu links.
Comment #31
rattusrattus CreditAttribution: rattusrattus commentedSee #2535070: Allow theming of cart menu link title for a patch to provide a theme funciton which can be overridden to alter the menu link title.
Comment #32
thirdender CreditAttribution: thirdender commentedI wanted to use the Commerce Cart module provided menu link, but I needed it in the
user-menu
menu instead of thenavigation
menu. Both the 'cart' and 'cart/my' items had to be moved to the new menu before they would appear in the UI. The following code was necessary to move the link:Comment #33
danielb CreditAttribution: danielb commented@ #32 Moving a menu item to another menu does not require any code, you can just do it by editing the menu item via the UI and changing it's parent.
Here is some code for hiding the Shopping Cart link altogether if there are 0 items:
There's probably several ways to do that, but that's the way I concocted just now.
Comment #34
dkosbob CreditAttribution: dkosbob at Message Agency commentedString overrides in settings.php worked just fine for me for altering the menu label while retaining functionality.
Comment #35
nbaosullivan CreditAttribution: nbaosullivan commentedI ended up doing the following:
Comment #36
voodi777 CreditAttribution: voodi777 commentedShow product in cart by product count :
Comment #37
voodi777 CreditAttribution: voodi777 commentedShow product in cart by product count :
Comment #38
voodi777 CreditAttribution: voodi777 commentedShow product in cart by product count :