Announcement

Collapse
No announcement yet.

Calculations in Product Template

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

    Calculations in Product Template

    To Start I am using Developer V7.

    I am building a wholesale site that requires login. All prices are the same regardless of account. All the prices are set up as retail prices, no bulk prices or adjustments etc.

    What I want to do in my ProductLIne Template is customize to show

    MSRP
    Your Price
    Your Profit

    what I thought was take the cost of the item from Actinic NETQUOTEVAR:PRODUCTPRICE and multiply it by 2 to get MSRP. I then wanted to subtract "MRSP" from "Your Price" to get "Your Profit"

    I pieced together some code I found in the community:
    Code:
    <script type="text/javascript">
     var price = 'NETQUOTEVAR:PRODUCTPRICE';
     var cost = 0;
     price = price.replace(/,/g,"");     	// remove all commas
     price = price.replace(/./g,".");    	// restore decimal point
     price = price.replace(/£|$/g,"£");    // fix £ and $ to just £ (so we can fiddle with it later)
     var pbits = price.match(/(£\d+\.\d\d)/);	// now look for first £n.nn 
     if ( pbits != null )
      {
      cost =  pbits[1].replace(/£/,"") - 0;
        	// now remove that £ and make numeric<br>
      }
    
    
    //var num= cost;
    var cost2= cost * 2;
    var result = cost2.toFixed(2); 
    document.write('$' + result); 
    //-->
    </script>

    the equation works in View Offline Preview in Actinic but not when I upload.

    Any suggestions?

    #2
    Can one of our script gurus take a look at this bit of code please.

    Kind regards,
    Bruce King
    SellerDeck

    Comment


      #3
      This might be your problem - not sure what

      Code:
      price = price.replace(/./g,".");    	// restore decimal point
      is meant to achieve? A "." in a regular expression matches any character that isn't whitespace, so if you want to match an actual ".", you need to escape it with a backslash:

      Code:
      price = price.replace(/\./g,".");    	// restore decimal point
      But that's just replacing it with the same character! I just removed this line. Your code as it is gives me $0.00, with amendment gives me a proper figure (double the netquotevar value).
      www.gbradley.co.uk
      Web Development, Actinic Patches, Scripts & more

      Comment

      Working...
      X