E-Commerce Suite - Empty Cart

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
hexdj
Power Poster
Power Poster
Posts: 415
Joined: Sat Mar 24, 2007 8:28 am

E-Commerce Suite - Empty Cart

Post by hexdj »

HOW TO EMPTY THE WHOLE CART
==========================
You will need to have the CGSimpleSmarty module for this to work

I needed an Empty Cart button in my View Cart template, so at the bottom (but still within the {$formstart}{$formend} tags) I added this button:

Code: Select all

<button type="submit" name="empty_cart" value="empty">Empty Cart</button>
Now this will submit the value "empty" when the button is clicked, so then we catch it at the very top of the View Cart template, like this:

Code: Select all

{*=== $smarty.post.empty_cart is the same as $_POST['empty_cart'] ===*}
{if $smarty.post.empty_cart=="empty"}
   {*=== this next line clears the session for Cart ===*}
   {session_erase var='cgcart'}
  <p>Your cart has been cleared.</p>
{else}
   {*=== Cart has no items... ===*}
   {if !isset($cartitems) || count($cartitems) == 0 }
      <p>Your cart is empty.</p>
   {else}
      {*=== display all the products... rest of the template goes here ===*}
      {*=== .... ===*}
   {/if}
{/if}
That's it, the Button will clear your whole Cart when clicked.


More tips soon...
Last edited by hexdj on Sat Jul 31, 2010 7:08 am, edited 1 time in total.
inyerface
Forum Members
Forum Members
Posts: 191
Joined: Mon Nov 26, 2007 4:46 pm

Re: E-Commerce Suite - Empty Cart

Post by inyerface »

Very cool. 3 thumbs up for sure!
Post Reply

Return to “Tips and Tricks”