Announcement

Collapse
No announcement yet.

Cart Contents

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

    Cart Contents

    I am currently using the follwing bit of script for showing the card contents:

    Code:
    if (getCartItem(3) < 1)
    {
    	document.write("Your cart is empty");
    }
    
    else
    
    {	
    	document.write ("NETQUOTEVAR:CARTCOOKIEITEMS&nbsp;" + getCartItem(3)+"&nbsp;<BR>");
    	document.write("NETQUOTEVAR:CARTCOOKIEVALUE&nbsp;" + getCartItem(1));
    }
    This works fine except that the value displayed from getCartItem(1) returns a price including VAT. Is there any way of accuratly getting an ex vat total displayed there?

    Cheers
    Matt
    Actinic User since v.3

    Custom Actinic Site Specialist:
    <a href="http://www.glowsticksdirect.co.uk/">GlowSticksDirect.co.uk</a>
    <a href="http://www.digishopdirect.co.uk/">DigiShopDirect.co.uk</a>
    <a href="http://www.calibreshopping.co.uk/">CalibreShopping.co.uk</a>

    #2
    If ALL your prices include VAT then you could always try replacing:-

    getCartItem(1)

    with:-

    '£' + (getCartItem(1).substring(1) / 1.175)

    This works if you only display a single price (not 2 currencies).

    However you might need some additional code to round it to 2 decimal digits.

    Norman.
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      I guessed that would be the case - I was going to do something similar if there was no other option anyway.

      Cheers
      Matt
      Actinic User since v.3

      Custom Actinic Site Specialist:
      <a href="http://www.glowsticksdirect.co.uk/">GlowSticksDirect.co.uk</a>
      <a href="http://www.digishopdirect.co.uk/">DigiShopDirect.co.uk</a>
      <a href="http://www.calibreshopping.co.uk/">CalibreShopping.co.uk</a>

      Comment


        #4
        Also (to save you the time trying it out) I tried calling getcartitem(0) through getcartitem(10) just in case there were some additional values available with no luck.

        Norman
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment


          #5
          Well, it transpires that the problem is a little more difficult the 1st thought.

          getCartItem(1) does not return a standard string like "£123,45.67", it actually returns something along the lines of:

          "&amp;#163;123&amp;#44;45&amp;#46;67"

          Which of course we all knew would happen(!). So in order to do any sort of mathematical calculation we need to strip out the html characters and turn it into a float.

          To strip the characters, perform the calculation then return a nice formatted string complete with £'s and 000's commas, I wrote the following javascript function in a .js file:
          Code:
          function formatCurrency(num) {
          	num = num.toString().replace(/\£|\,/g,'');
          	num = num.replace("&amp;#163;","");  // Strip £ sign
          	num = num.replace("&amp;#44;","");   // Strip commans
          	num = num.replace("&amp;#46;",".");   // Replaces html perios with true periods
          	num = num / 1.175;
          	if(isNaN(num))
          		num = "0";
          		sign = (num == (num = Math.abs(num)));
          		num = Math.floor(num*100+0.50000000001);
          		pence = num%100;
          		num = Math.floor(num/100).toString();
          	if(pence<10)
          		pence = "0" + pence;
          	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
          		num = num.substring(0,num.length-(4*i+3))+','+
          		num.substring(num.length-(4*i+3));
          	return (((sign)?'':'-') + '£' + num + '.' + pence);
          }
          Then, to get a net price displayed in the quick cart, rather than using:
          Code:
          document.write("NETQUOTEVAR:CARTCOOKIEVALUE&amp;nbsp;" + getCartItem(1));
          I can use
          Code:
          document.write("NETQUOTEVAR:CARTCOOKIEVALUE&amp;nbsp;" + formatCurrency(getCartItem(1)));
          In any page that include the .js file with the fuction in!

          Hopefully this might help someone and save them the hours it took me to work out.
          Matt
          Actinic User since v.3

          Custom Actinic Site Specialist:
          <a href="http://www.glowsticksdirect.co.uk/">GlowSticksDirect.co.uk</a>
          <a href="http://www.digishopdirect.co.uk/">DigiShopDirect.co.uk</a>
          <a href="http://www.calibreshopping.co.uk/">CalibreShopping.co.uk</a>

          Comment


            #6
            Thanks Matt - a useful function.

            Comment

            Working...
            X