Announcement

Collapse
No announcement yet.

Emptying the Shopping Cart and Address in One Click or when people 'Cancel' Checkout

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Emptying the Shopping Cart and Address in One Click or when people 'Cancel' Checkout

    I just thought I would share something I spent a long time looking for! It should hopefully be more easily found now by others!

    This little trick is great for emptying the Cart Contents AND the address details in one click of a button. It is helpful for confused customers to start again and also for operators needing to use the front end for whatever reasons.

    We adapted the code slightly to have a button that simply reads 'Reset Order' which we find very useful!
    ----------------------
    Advanced Users Guide
    Version 1.2.7
    ----------------------
    Emptying The Cart When People Leave The Checkout

    This JavaScript function will empty your customer's shopping cart when they click the 'Cancel' button on the checkout. It is useful as sometimes i
    t is confusing for customers if they still have items in their shopping cart, when they think they have cancelled the transaction.

    To begin, place the following JavaScript functions in the <head> area of the overall page layout that is being used in the checkout. You can verify this in the 'Checkout Pages Layout' field in 'Settings | Site Options | Layouts'.

    Add it in just above the closing </head> tag.

    <script language="Javascript" type="text/javascript">
    function createCookie(name,value,days) {
    if (days)
    {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path
    =/";
    }

    function CancelOrder() {
    if (confirm('This will clear your order and address details
    completely.\nClick "View Cart" to change your order.\nDo you wish to
    proceed?') == true)
    {
    createCookie("ACTINIC_CART","",-2);
    createCookie("CART_CONTENT","",-2);
    createCookie("CART_COUNT","",-2);
    createCookie("CART_TOTAL","",-2);
    createCookie("ACTINIC_BUSINESS","",-2);
    createCookie("ACTINIC_REFERRER","",-2);
    window.location.href = 'http://www.YOURSITE.com/RETURN-PAGE';
    }
    }
    </script>

    Replace 'http://www.YOURSITE.com/RETURN-PAGE' with the location of a page you want to take customers to.

    Then go to 'Design | Library | Layouts' and locate the 'Checkout Button' group. Within it, locate 'Checkout Cancel Button' and double-click on it to
    open it.

    Replace the code in the layout with the following:

    <input type="button" name="ACTION" value="<actinic:variable
    encoding="html" name="CancelButton" />" class="normal-button"
    onclick="CancelOrder();" />

    #2
    I tried the above code but it produced a JavaScript error. I checked and double checked that I had copied it correctly and put it in the right place but I still get a JavaScript error message generated. Any ideas?

    Comment


      #3
      Lumps of code posted here need [c o d e] and [/c o d e] (typed without the spaces) around them so they preserve formatting and don't contain extraneous new lines.

      Here it is corrected:
      Code:
      <script language="Javascript" type="text/javascript"> 
      function createCookie(name,value,days) { 
      	if (days) 
      		{ 
      		var date = new Date(); 
      		date.setTime(date.getTime()+(days*24*60*60*1000)); 
      		var expires = "; expires="+date.toGMTString(); 
      		} 
      	else var expires = ""; 
      	document.cookie = name+"="+value+expires+"; path=/"; 
      }
      
      function CancelOrder() { 
      	if (confirm('This will clear your order and address details completely.\nClick "View Cart" to change your order.\nDo you wish to proceed?') == true) 
      		{ 
      		createCookie("ACTINIC_CART","",-2); 
      		createCookie("CART_CONTENT","",-2); 
      		createCookie("CART_COUNT","",-2); 
      		createCookie("CART_TOTAL","",-2); 
      		createCookie("ACTINIC_BUSINESS","",-2); 
      		createCookie("ACTINIC_REFERRER","",-2); 
      		window.location.href = 'http://www.YOURSITE.com/RETURN-PAGE'; 
      		} 
      }
      </script>
      Use in conjunction with the notes in post #1 above.
      Norman - www.drillpine.biz
      Edinburgh, U K / Bitez, Turkey

      Comment


        #4
        Thanks for the tip Norman - that will teach me to be helpful!

        Another thing I have noticed with this code is that it will only do the job once! The second time it appears to do the job but once you go to another page and click back in the cart the products are still there..?!

        Are there some time restraints set out by the code?

        Comment


          #5
          Cart and customer details are stored in .SESSION files, one created on the server per unique shopper.

          The Cart Cookie is only used as storage between the Perl scripts that create / use the .SESSION files and the HTML pages so will probably get re-created whenever the Cart is viewed.

          Looks like another approach would be needed.
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #6
            This is a useful bit of code - so it is a pity it fails to clear the cart after being used just once.

            Thinking about this a bit further, it seems utterly bizarre that a company like SellerDeck that has been producing shopping carts for some time has not, so far, equipped their Shopping Cart with a "Cancel Order" button that actually works.

            Currently, the way it works (or rather doesn't work!) doesn't cancel the order at all. You have to unprompted ...."find" your way to View Cart and cancel from there. Surely they can do better than this!?

            Now ... will SellerDeck respond to this criticism of their shopping cart?

            Comment

            Working...
            X