Announcement

Collapse
No announcement yet.

Clearing Cookies

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

    Clearing Cookies

    Hello all,

    On one of our sites we have a function that clears the order details by resetting the cookie for the cart and also related a shipping feature I have implemented.

    However, we have had reports of it not clearing the order at times. Basically it should reset the ACTINIC_CART, CART_CONTENT and CART_TOTAL cookies to values of "" with expiry dates of 2 days ago.

    If you add an item to the cart it should produce a link on the Order Summary saying 'Clear Order'. Clicking this should reload the page, having cleared the cookies.

    Can a few of you please try this out, to see if it causes any noticeable failures? I have tested it in IE, Netscape, Mozilla and Opera and cannot get it to fall over.

    The 'View Cart' page should state that the order is empty after pressing the link.

    Your thoughts are appreciated.

    Thank you. The code that runs this is below:

    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 ClearDetails()
    {
    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.reload();
    }
    }
    http://www.johnsons-seeds.com - Actinic plugins, remote add to cart and custom CMS
    http://www.dtbrownseeds.co.uk - More seeds and plants....
    http://www.mr-fothergills.co.uk - Well it used to be Actinic...

    #2
    It works very nicely for me: Win XP, SP2, IE 6.0.29, Zonealarm,

    Thanks for sharing it on the forum.

    Mike
    -----------------------------------------

    First Tackle - Fly Fishing and Game Angling

    -----------------------------------------

    Comment


      #3
      Works for me on Windoze 2000, IE 6.0.2800

      Andrew
      Andrew Fish
      Http://www.BatteryShed.co.uk
      For all your battery requirements at prices less than in the high street.
      "Batteries without the overcharging"

      Comment


        #4
        Works for me

        Windows 2000 (NT). Cheers for listing the code. The site looks good, by the way

        Comment


          #5
          Originally posted by DaveT
          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 ClearDetails()
          {
          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.reload();
          }
          }
          That looks like just what I need, but where do I put the code and how do I call it from a button press...?
          John

          Comment


            #6
            You paste that code into the head of your template between:

            <script type="text/javascript">
            <!--
            function....{
            .
            .
            .
            }
            //-->
            </script>

            Then call it:

            <input type="button" value="Cancel" onclick="ClearDetails()" />

            And then save and test.
            http://www.johnsons-seeds.com - Actinic plugins, remote add to cart and custom CMS
            http://www.dtbrownseeds.co.uk - More seeds and plants....
            http://www.mr-fothergills.co.uk - Well it used to be Actinic...

            Comment


              #7
              cool. thanks, I'll try that as soon as I get my payment problem sorted! (see other thread)
              John

              Comment


                #8
                Hi,
                Does that code go into the ACT_Primary.html and brochure.html pages head section?

                Thanks
                Sellerdeck Business Plus 12.0.1.NBLA

                Comment


                  #9
                  Hi there

                  The following goes into the head section of "Act_Primary.html" and "Act_BrochurePrimary.html"

                  Code:
                  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 ClearDetails()
                  {
                  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.reload();
                  }
                  }
                  The following would be placed in any part of the body, where you want to show it.

                  Code:
                  <input type="button" value="Cancel" onclick="ClearDetails()" />
                  Kind Regards
                  Nadeem Rasool
                  SellerDeck Development

                  Comment


                    #10
                    Thanks, works fine. Tested with IE 6 and Firefox.
                    Sellerdeck Business Plus 12.0.1.NBLA

                    Comment


                      #11
                      I noticed an issue when clicking on cancel when in checkout, I get a script error page, when I click back the cart shows items again so I have to go back to a secton page and then cancel. I changed the reload page (last line) to:

                      window.location.reload("http://www.mysite.com/acatalog/");

                      This won't cause any problems will it?
                      Sellerdeck Business Plus 12.0.1.NBLA

                      Comment


                        #12
                        This won't cause any problems will it?
                        Not sure. There's only one way to find out - create lots of test transactions with a variety of browsers.

                        Comment


                          #13
                          Regarding the code for this:

                          It's working fine for me and, I assume, everyone else but I have a user who has identified it as a potential cause of an error he is getting (Norton Internet Security flagging it up as dodgy). Ignoring this, I have a question:

                          Can someone explain the first few lines of the JS code please? Does it create the cookie every time the page is loaded (as it's sitting inside Act_Primary), or only when the function is run? i.e. by clicking a button (or however it's implemented)


                          Thanks,

                          Ryan

                          Comment


                            #14
                            The first bit of the code defines the function, but it only runs (and creates the cookie) when the button is clicked.

                            Mike
                            -----------------------------------------

                            First Tackle - Fly Fishing and Game Angling

                            -----------------------------------------

                            Comment


                              #15
                              Cheers Mike, that's what i thought. As to creating a cookie, it's overwriting an existing cookie with invalid times to reset the fields, yep? It doesn't create anything new or out of the ordinary?


                              Incidentally, the NIS error was the "HTTP Cookie Monster Attack" which has been discussed briefly here on the boards before. It seems that it's NIS that is in error, and flags it up as a false positive. My user thought that it was the above code, but it now seems it isn't, as it's only involved when deliberately clicking a button.

                              Comment

                              Working...
                              X