Twitter RSS

simpleCart(js) Version 2.0 Released!

Monday, August 10th, 2009

We are happy to announce the release of simpleCart(js) version 2.0 today.  We have been working hard to add several features that you all have requested, and we’re excited to get this script in your hands.  There are several new features, including GoogleCheckout, easy currency settings, tax, shipping, and a new method for adding items to your cart that requires no javascript, and allows for different inputs and options. There is also a brand new site to go along with this update: simplecartjs.com .  Please take a minute to check out all the new features, documentation, and demo.  Thanks to all those who have been helping test for the past few weeks, we couldn’t have released this new version without your help.

Upgrading your version

If you are already using simpleCart(js), the only thing you need to change to use the new script is how you add it to your page:


<script src="simpleCart.js" type="text/javascript"></script> <script type="text/javascript">
simpleCart.email = "you@yours.com";
</script>

Check out the website, simplecartjs.com to learn about the new features, and let us know what you think!


Javascript Number.toCurrency()

Friday, July 31st, 2009

While working on simpleCart(js) 2.0 and a few shopping carts for clients, I found myself writing several helper functions for formatting strings and numbers.  One of the most useful helpers was a toCurrency() method for numbers:


var myNumber = 8.3;

alert( myNumber.toCurrency() );   //alerts "$8.30"

myNumber = 119427.23529;

alert( myNumber.toCurrency() );    //alerts "$119,427.24"

myNumber = 1231;

alert( myNumber.toCurrency( "€" ) );   //alerts "€1,231.00"

The dollar sign is default, but you can replace it with any symbol in the function call.

Just copy this code to your js file and enjoy! (This code also implements a reverse() method for strings that you might find useful.)


String.prototype.reverse=function(){
return this.split("").reverse().join("");
}
Number.prototype.withCommas=function(){
var x=6,y=parseFloat(this).toFixed(2).toString().reverse();
while(x<y.length){y=y.substring(0,x)+","+y.substring(x);x+=4;}
return y.reverse();
}
Number.prototype.toCurrency=function(){
return(arguments[0]?arguments[0]:"$")+this.withCommas();
}