Announcement

Collapse
No announcement yet.

spend another x for free delivery...

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

    spend another x for free delivery...

    next to my shopping cart i have the text: to qualify for free delivery spend another...

    then the code:

    Code:
       <script language="javascript" type="text/javascript">
    	   <!--
    	   document.write(100 - getCartItem(1));
    	   // -->
       </script>
    which i thought would retrieve the current cart total and take it from £100 and output the differrence, it doesn't...

    does anyone know how to do this?

    #2
    Here you go, tested and working!

    Code:
    <script language="javascript" type="text/javascript">
    	var left;
    	if (getCartItem(1) >= 100) {
    		document.write("You have qualified for free shipping!");
    	}
    	else {
    		left = 100 - getCartItem(1);
    		document.write("You need to spend £"+left+" to obtain free shipping!");
    	}
    </script>
    Changed "100" to your free shipping cost.
    Richard Smith
    www.hamradio.co.uk

    Comment


      #3
      thankyou very much! great bit of code

      EDIT:
      actually... no it doesnt yet

      when the code first went in it said "Spend another £100 to qualify for free delivery" but when you add something to the basket it says "Spend another £NaN to qualify for free delivery"...

      also, it stays like this even when the cart goes over £100, is it something to do with the only valid integer in the GetCartItem(1) variable is 0, which works, but all other states (i.e. when something is in the cart) the variable contains a £ sign or something like that?

      i'm gessing if thats the case then this isnt even possible?

      Comment


        #4
        Working on a fix.. just taking a while!

        * or trying, just got one small problem *

        See below ^^
        Richard Smith
        www.hamradio.co.uk

        Comment


          #5
          Finally worked it out, javascript isnt my native language..

          Code:
          <script language="javascript" type="text/javascript">
          function de(prc) {
          	var data;
          	data = new String(prc);
          	data = data.split(" ");
          	fil = "&#163;";
          	var i, endata = "";
          	for (i = 0; i < data[0].length; i++) { 
          		var c = data[0].charAt(i);
          		if (fil.indexOf(c) == -1) { endata += c; }
          	}
          	return endata;
          }
          
          var left;
          price = de(getCartItem(1));
          if (price >= 100) {
          	document.write("You have qualified for free shipping!");
          }
          else {
          	left = 100 - price;
          	document.write("You need to spend £"+left+" to obtain free shipping!");
          }
          </script>
          You can place the function command into the actinic javascript file if you want.

          Shout if you get any more problems.
          Richard Smith
          www.hamradio.co.uk

          Comment


            #6
            Good one Richard.
            One for the AUG perhaps Chris?...

            Comment


              #7
              Yep, I'll add this into the AUG when I next update it. Thanks!

              Comment


                #8
                i do plan to shift the js into an external file once i get it working but for now i just copied and pasted that but still just getting NaN instead of a number...

                Richard did this work on one of your actinic sites or did you just write it theoretically? i can see the logic as i know a teeny bit of js and it looks sound but still not working this end - any ideas?

                Comment


                  #9
                  Woops, sorry I was using a test subject within the script.. not live - but just change this line:

                  Code:
                  	fil = "& # 1 6 3;";
                  Remove the white spaces in the " " as it keeps switching it.. the forum coding -.-
                  Richard Smith
                  www.hamradio.co.uk

                  Comment


                    #10
                    hi richard,

                    its getting closer but still not there unfortunately - when i first tried it i added £40 to the basket and it qualified me for free shipping (despite the js obviously stating 100) and then when a collegue tried it it gave the "spend another..." statement but got the maths wrong (he purchsaed £3 worth and it said spend another forty something...)

                    sorry about this - the work is very muh appreciated.

                    Comment


                      #11
                      Simon can you pop me an email (richard@mlands.co.uk) with the link to were this problem is please.. as it seemed to work live on our site *cries*

                      We will get there soon enough!
                      Richard Smith
                      www.hamradio.co.uk

                      Comment


                        #12
                        Solved the problem!

                        Code:
                        <script language="javascript" type="text/javascript">
                        function de(prc) {
                        	var data, endata;
                        	data = new String(prc);
                        	data = data.split("& # 3 2 ;");
                        	endata = cut(data[0]);
                        	return endata;
                        }
                        function cut(dpt) {
                        	stng = dpt.replace("& # 1 6 3 ;", "");
                        	stang = stng.replace("& # 4 6 ;", ".");
                        	return stang;
                        }
                        var left;
                        price = de(getCartItem(1));
                        if (price >= 100) {
                        	document.write("You have qualified for free shipping!");
                        }
                        else {
                        	left = 100 - price;
                        	document.write("You need to spend £"+left+" to obtain free shipping!");
                        }
                        </script>
                        Richard Smith
                        www.hamradio.co.uk

                        Comment


                          #13
                          Free Delivery Script not working

                          I think I must be missing something, I've added the script to the Shopping Cart trying both the script here and the AUG (presume it's the same) but the only message I get is "You need to spend £NaN to obtain free shipping!"
                          It looks ok in preview but does not work on site!

                          I've taken it off as it looks stupid, anyone know what I'm doing wrong?, is there something else I should be doing apart from pasting the script in the Shopping Cart template?

                          Comment


                            #14
                            I just tried this code and the one in the AUG and they work fine, perhaps something on the server preventing it from displaying correctly as you say it appears fine in the preview.

                            Kind regards,
                            Bruce King
                            SellerDeck

                            Comment

                            Working...
                            X