Discussions

Empty Shopping Cart Link

I have been scouring the net looking for information on how to create an "Empty Shopping Cart" button/link--without success.

Essentially, my concern is, that if users add contents to their cart, it keeps the cart block display ad infinitum seemingly, without ever allowing them to empty it. For my User Interfaces, this could prove to be quite pesky.

Thanks,

Dale

Tags: 
Posted: Aug 31, 2013

Comments

dale brendan on September 1, 2013

Out of urgent need, I ended up forking this module: https://drupal.org/project/commerce_empty_cart_paths - to basically do the opposite of what it is intended to do. i.e. set a path to empty the cart, instead of setting all paths in which the cart does not empty. Kind of on a deadline, so sorry for the hack! ...but, eh, sometimes you just have to get the job done.

When I have a bit more time, I will go back and patch this module, but being that I could not find a solution for this anywhere, I figured I would post it here to help some lost soul between then and now. Again, sorry for the fork. :)

This is what I did:

  1. Edit this function: commerce_empty_cart_paths_page_alter(&$page) - and switched it so that instead of looking for all paths on which to not empty the shopping cart, I told it to look for just 1 path on which to empty the shopping cart.
  2. Within that if conditional, after empty the cart, I added a simple drupal_goto() redirect back to the users' dashboard
  3. I created a blank page with my desired path (e.g. cart/empty or products/empty, etc).
  4. I added an additional global text area to the bottom of the: Commerce - Shopping Cart Block with a link to the empty cart path
  5. I styled the block accordingly

As I said, time allowing I will go back and patch this module to allow for either: all empty non-empty cart paths (by default) or a single empty cart path.

Good luck.