1 Reply Latest reply: Aug 15, 2013 8:19 AM by William Phelps RSS

    Cookie related functionality for shopping cart site

    myinception

      I have a requirement for a shopping cart site.

       

      • - Users cart should be retained for 90 days. If the user closes the browser and opens it, the cart should still be there for 90 days.
      • - If the user manually clears the browser cache, the cart will be lost
      • - The users cart is saved only in the device that they are currently on. If the same user access the site, from a different device this cart information saved previously cannot be accessed

       

      Can anyone guide me regarding the above points with sample code of the same? I think I have to call a service from Site Studio template and write the code in Java.

        • 1. Re: Cookie related functionality for shopping cart site
          William Phelps

          Since this thread seems to be getting little traction, I'll bite.

           

          Let me see if I understand the requirements, because numbers two and three just seem, well, weird.

          - Requirement 1 says "Save the data for 90 days". Clear enough.

           

          - Requirement 2 says "If the user clears the browser cache, the data should be discarded."  Why does clearing the cache need to clear the data?  Does it actually need to do so? Or are you saying "this is a problem I need to overcome.  If the user clears the cache, their data is lost.  I need to save the data in such a case."  The requirement as originally stated sounds more like a problem statement that a requirement.  Please clarify.

           

          - Requirement 3 says "The user can only access the data from one device."  Again, is this the "requirement" or more of a problem statement?

           

          So, depending on the data involved, cookies are a less-than-optimal way of storing this kind of data.  A user can refuse to allow cookies, so that breaks your design immediately.  Depending on the amount of data, a browser's cookie mechanism may limit the amount of data stored in the cookie.  You'd also be coding to the least common denominator browser to make this solution work, as each browser's cookie implementation varies.

           

          If you are dead-set on pursuing this approach, there really isn't much code you need if you are using SiteStudio template pages.  There are already <$getCookie$> and <$setCookie$> IDOC functions.  You can get that from the scripting reference.

           

          A better way though, in my opinion, is to look at how Content Server creates the pne_portal.hda file that is used to store user preferences.  That's actually a pretty solid way to save the data, as you get out of cookie limitations, plus the data is shareable across devices.  I don't have any sample code that I can access at the moment, but if you look in the code for "editTopics", you should be able to get an idea of what's happening.