Announcement

Collapse
No announcement yet.

Show cart summary on my own page?

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

    Show cart summary on my own page?

    Hi all,

    I've created my own pages with products and "add to cart" buttons, it works fine.

    Anyway, I would like to add a bit that shows a summary of the cart contents, such as number of items and total cart value. I've tried inserting a bit of code that I've seen:

    <script language="JavaScript">
    <!--
    document.write("Items:" + getCartItem(3)+"&nbsp;<br>");
    document.write("Value:" + getCartItem(1));
    // -->
    </script>

    see my little test page: http://www.peakelec.co.uk/acatalog/jz_test.html

    But it just shows zero all the time for both the number of items and the value.

    What am I doing wrong?

    Cheers,
    Jez Siddons
    Peak Electronic Design Limited

    #2
    function getCartItem(nIndex)
    {
    var act_cart= getCookie("CART_CONTENT")
    var sTemp =(act_cart != null) ? sTemp=act_cart.split("\t"):0;
    return (sTemp.length > 0) ? sTemp[nIndex] : 0;
    }

    ...is the javascript in actinicextras that displays your data.

    it relys on a cookie, to fetch the cart contents. perhaps you'r cart is not saving the cookie when an item is added?

    Comment


      #3
      Hi gabrielcrowe,

      Many thanks for the reply. I've just tried your code but it doesn't work, maybe I'm putting it in incorrectly. Do I just plop that bit of code into my html then, say into a cell of a table?

      Cheers,
      Jez
      Jez Siddons
      Peak Electronic Design Limited

      Comment


        #4
        lol, no, that code was not to put in your page, you allready have it in your pages.

        i was demonstrating that perhaps during your modifications of the shop, perhaps you'd removed the code responsible for setting cookies, as an item is added to the cart.

        there are a number of knowledgebase article on this topic and references in the advanced userguide.

        Comment


          #5
          Doh! Ok, so maybe my original code was kind of ok (although it doesn't work).

          I do know that items are being added ok as I can click my "View Cart / Checkout" button on the top bar and it shows stuff fine. I just want to permanently display the little summary.

          I'm not 100% sure I understand your answer then, sorry :-/

          Cheers,
          Jez Siddons
          Peak Electronic Design Limited

          Comment


            #6
            to test your items are being added to cart cookie, make a new document in notepad and upload it via ftp.

            Code:
            <script language="JavaScript">
            
            function getCookie(sName) 
                {
                var sCookiecrumbs = document.cookie.split("; "); 	// break cookie into crumbs array
                var sNextcrumb
                for (var i=0; i < sCookiecrumbs.length; i++) 
            	{
            	sNextcrumb = sCookiecrumbs[i].split("=");	// break into name and value
            	if (sNextcrumb[0] == sName)			// if name matches
            	    {
            	     return unescape(sNextcrumb[1]); 		// return value
            	    }
            	}
            	return null;
                }
            
            document.write(getCookie('CART_CONTENT'));
            // -->
            
            </script>
            save it as something like 'test.htm' and put it in your site root. in fact anywhere on your site will do, as long as you can get to it in a browser.

            it'll display anything that has been stored in the cart cookie.

            add some gubbins to your cart, then view this page, what happens?

            Comment


              #7
              i expanded the code, if anyone else would like a sneaky peek at their own cart cookie:

              Code:
              <script language="JavaScript">
              
              function getCookie(sName) 
                  {
                  var sCookiecrumbs = document.cookie.split("; "); 	// break cookie into crumbs array
                  var sNextcrumb
                  for (var i=0; i < sCookiecrumbs.length; i++) 
              	{
              	sNextcrumb = sCookiecrumbs[i].split("=");	// break into name and value
              	if (sNextcrumb[0] == sName)			// if name matches
              	    {
              	     return unescape(sNextcrumb[1]); 		// return value
              	    }
              	}
              	return null;
                  }
              	
              	
              function getCartItem(nIndex)
              	{
              	var act_cart= getCookie("CART_CONTENT")
              	var sTemp =(act_cart != null) ? sTemp=act_cart.split("\t"):0;
              	return (sTemp.length > 0) ? sTemp[nIndex] : 0;
              	}	
              
              document.write("<b>Raw Cart Cookie:</b><br>" + getCookie('CART_CONTENT')+"&nbsp;<br><br><br>");
              document.write("<b>Parsed:</b><br>");
              document.write("Items:" + getCartItem(3)+"&nbsp;<br>");
              document.write("Value:" + getCartItem(1));
              // -->
              </script>
              NOTE: that the 'getCookie' and 'getCartItem' subs are actually a direct lift from the actiniccore and actinicextras scripts, that are included in your pages normally.

              Comment


                #8
                Many thanks for the suggestions.

                I created a file:
                http://www.peakelec.co.uk/acatalog/jz_test.html

                I inserted the short code example you made and it simply showed "null". I then tried the expanded code and it displayed something like:

                Raw Cart Cookie:
                null
                Parsed:
                Items:0
                Value:0

                Yet, if I click on the "show cart" it shows the shtuff.

                What are your thoughts.

                By the way, many thanks for your efforts so far!

                Cheers,
                Jez Siddons
                Peak Electronic Design Limited

                Comment


                  #9
                  your cart items are stored on the server,

                  when you add to cart, these items information are placed in a cookie.

                  this cookie is what we are after to display this information.

                  the code shows that your cookie is not being set.

                  can anyone shed any light on this?

                  Comment


                    #10
                    on a side note, i need some lcd displays, i'll bookmark you.

                    much cheaper than crystalfontz

                    Comment


                      #11
                      Could it be that the cookie is being created ok (as the View Cart link works at the top of my page) but is stored in a path that I am not referring to correctly with the Javascript??

                      I do know that Demon (who I am hosted with) have a very odd path structure.

                      The odd thing is, everything with my cart and checkout work perfectly, it's just add on bit of code that doesn't do the biz, I'm stumped.

                      By the way gabrielcrowe, your site is just stunning.

                      Cheers,
                      Jez
                      Jez Siddons
                      Peak Electronic Design Limited

                      Comment


                        #12
                        By the way gabrielcrowe, your site is just stunning.
                        You;re the first to comment, it was very hard work, getting it where it is today, and its still far from done.

                        and quite frankly, i'll ahve to start all over again. V8 butchers my customisation.




                        I do know that Demon (who I am hosted with) have a very odd path structure.
                        cookies are stored locally, on the browser. you ahve no control over the location. and therefore, it cant be stored in the wrong place.

                        perhaps you removed something from the templates, important to the creation of cookies?

                        Comment


                          #13
                          and quite frankly, i'll ahve to start all over again. V8 butchers my customisation.
                          Hi there - please pass on your snapshot to us via v8beta@actinic.co.uk and we can take a look at it and see what happens during upgrade. Who knows? Maybe it will work much better for you by the time v8 is released.

                          Comment


                            #14
                            yes, i'm hoping this is the case. but to be honest, i'm going to strip out the tables, now that actinic has removed a lot of wierd tags...

                            so, i'll be redoing the templates from scratch anyhow.

                            has this cookie problem been fixed or is it still broke?
                            Last edited by gabrielcrowe; 12-Jul-2006, 09:12 AM. Reason: straying from the issue... lol.

                            Comment


                              #15
                              Hi gabrielcrowe,

                              I've left it for now, I can't get the cart summary to work in my pages. Apart from that, everything works fine, the cart, checkout and so on. So cookies must be working mustn't they?

                              Cheers,
                              Jez

                              PS. With regard to V8, "if it ain't broke" and all that! Why not stick with V7 now you've got it to sing to your own tune?? I personally resent the upgrade gravy train, ho hum.
                              Jez Siddons
                              Peak Electronic Design Limited

                              Comment

                              Working...
                              X