simpleCart.add( values )


  • values: name/value map of an item to be added to the cart


  • simpleCart.Item object if successfully added

Add an item to the cart

    name: "Cool T-Shirt" ,
    price: 45.99 ,
    size: "Small" ,
    quantity: 3

If a price is not supplied, it is set to 0.

If a quantity is not supplied, it is set to 1.

If all of the fields match an item currently in the cart, simpleCart will increment that items quantity by the quantity supplied


  1. Jun 11, 2012

    adelphia  said:

    I have found this impossible to get working.  I’m not sure what I am doing wrong.

    I have tried a simple simpleCart.add({name:“Goofball”}) but all I get is an empty item with a value of ZERO (the value I was expecting, but it’s not giving the item a name.

    What I have to do is to use the .set(“name”,“Goofball”) to get the item to be added.

  2. Jun 13, 2012

    adelphia  said:

    OK.  To add a little more detail cause I’m stumped…

    My code is simple…

    var itemInfo = (valueCount == 1 ? document.forms[formName][inputName].value.split(”?”) : document.forms[formName][inputName][selectedItem].value.split(”?”));
    var itemName = itemInfo[0];
    var itemPrice = parseInt(itemInfo[1]).toFixed(2);
    var thisItem = simpleCart.add({name:itemName,price:itemPrice});

    But all I get added is a nullified item (no name and a zero price.

    Any ideas?

  3. Jun 13, 2012

    adelphia  said:

    OK. Sorted.  It’s the documentation again (sorry).  Instead of

    var thisItem = simpleCart.add({name:itemName,price:itemPrice});

    I used…

    var thisItem = simpleCart.add(“name=” + itemName,“price=” + itemPrice);

    Which works without a hitch…

Commenting is not available in this channel entry.