Closed (fixed)
Project:
Commerce Core
Version:
7.x-1.0
Component:
Cart
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
10 Sep 2011 at 19:39 UTC
Updated:
19 Nov 2016 at 15:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
rszrama commentedThere are no settings for this as is, though it may technically be possible through page altering. It's not something I've ever attempted, though. When we convert this block to be entirely a View, that should take care of it, since I believe you can hide a View display if empty.
Comment #2
darksnowThanks Ryan, I tried to put some PHP on a criteria to show the page, but couldn't work out how to get it to work.
It's not serious and I can live with the shopping cart being there for this project, though I just think it's a little untidy.
Again, thanks for the quick reply, I'll keep an eye on it.
Martin...
Comment #3
rszrama commentedCool, I'll see what we can do about converting those to Views entirely for 1.1. It's not that much work. The only reason I didn't do it earlier was I wasn't aware that Views 3.x was still supporting translatable interface text. Apparently it's just an option you have to choose before exporting the View. The only reason that might not go through would be theme template-ability.
Oh! But I just realized... you don't actually have to use the core cart block at all. You can still use the same View and just add a Block display to it. Disable the core block and voila! Hide when empty will probably work just fine.
Comment #4
darksnowCheers for that Ryan, that worked a treat.
I messed about with the views setup, got myself a Cart block and when it's empty, it doesn't appear.
Problem solved.
Comment #5
rszrama commentedExcellent! Glad to hear it.
Comment #6
darksnowIt should be noted that my testing through up a potential problem here.
You MUST make sure you add Order Status = Shopping Cart to the view filters, or any given user will see everything they've ever ordered in their cart and the remove from cart buttons won't work for those old line items.
Comment #7
skaughtuse a hook, of course:
presto, all gone.
Comment #8
urban farmer commentedSkaught, this may sound like a stupid question, but I am new to drupal. Where do I place the hook?
Comment #9
koushik12345 commentedThis is not correct. Please use this page (commerce/module/cart/commerce_cart.module)
/**
* Themes an empty shopping cart block's contents.
*/
function theme_commerce_cart_empty_block() {
return '
';
}
/**
* Themes an empty shopping cart page.
*/
function theme_commerce_cart_empty_page() {
return '
';
}
Comment #10
darksnow@urban farmer
The hook functions go in template.php for your theme, with the function name changed to match your theme name.
If you are a relative Drupal newbie though, then creating a view to display the contents of the cart might be easier for you since views automatically don't display if they get no results (unless you give them an empty text).
Comment #11
skaughtsorry, a hasty post. In templete.php is correct. i corrected my first code sample.
Comment #13
pitxels commentedI used the hook, but I returned nothing:
return '';Otherwise the Title of the block is still there, and the region of that block keep occupying space.
Comment #14
stieglitz commentedopps
Comment #15
tomrenner commentedI have created a small module that basically does nothing but add another cart block in the blocks section. The "Disappearing Shopping cart" will return NULL if there is no active order on the logged-in user, thus also no headline for the block.
Comment #16
tomrenner commentedJust found out: the module needs a slight adjustment for anonymous user:
needs to be changed to
Comment #17
dave bruns commentedJust chiming in with a few notes on hiding the cart when empty, by cloning the original block display in the view...
When I first did cloned the display, I got some weird memory problems and a very sluggish views display. Then, when I saved the newly cloned block and added the block to a region, I got a memory problem that prevented any page on the site (that would normally contain the shopping cart) from displaying.
Turns out that I needed to adjust the contextual filter to supply a default value of the "current user's cart order ID". This is (apparently, see http://bit.ly/JwXoUl) supplied to the default block through a variable. Without this default, my new block was trying to display all line items from every order on the site. Since this is an Ubercart to Commerce migration site, this was a big problem because there are a lot of previous orders. # 6 above mentions using "order status" as a filter, but I don't think this is needed as long as as the contextual filter is set up properly.
Once the filter was working the new block worked great (i.e. disappeared when empty) and I disabled the original block.
Comment #18
philippejadin commentedUsing solution #7 and returning nothing as explained in #13 works just fine.
Comment #19
gratefulsk commentedComment #20
donok commented#19 - thank you that was easy
fyi also added
cart
checkout/*
to the Pages tab in the block's configuration to keep it from showing on those pages
Thanks!
Comment #21
rowbotony commentedThanks #19 - super simple, works great!!
Comment #22
benjas commentedThanks #19 - worked for me as well. Remember to create a new block.
Comment #23
kurtfoster commented#19 is a great solution, the only thing I do differently is I create a new view rather than a new block in the same view as I move it around via features and I find it easier as a separate item.
Comment #24
Shyghar commentedI used the hook suggested in comment #7 and it work perfectly!
I simply return false to not display the empty cart block.
Thank you SKAUGHT.
Thanks to tomrenner for #9 for theme_commerce_cart_empty_page() hook ^^
Comment #25
hanskuiters commentedA bit old topic, but still relevant.
#19 doesn't work for me. For some reasen I can't get the view display to duplicate. Altering the original display with the suggested changes doesn't work eather. Might be something to do with a newer verison of Commerce?#7 works fine, I use it with the addiction of #13/#24.
Thanks for sharing.
EDIT:
I didn't read #19 very well. I indead needed to create a NEW display because the view only contains the master display. #19 works fine too.
Comment #26
argiepiano commented#19 works, but remember to also include the filter in #6. Thanks