wojodesign / simplecart-js

A simple javascript shopping cart that easily integrates with your current website.
simplecartjs.org
1.79k stars 490 forks source link

data or extra_data? #307

Closed m9dfukc closed 10 years ago

m9dfukc commented 11 years ago

I wanna store a customer address form inside the simpleCart object but can't get it working. Also there is some confusion if the variable is called "data" or "extra_data" - the documentation states "data" but looking into the code and on the issues forum it looks like the var is called "extra_data" - still I can't get it to work :(

Another question is how I can I receive this "extra data" without using the "beforeCheckout" event and if it's possible to store a nested object in there?

thanks Andreas

iamstevemckinney commented 11 years ago

When initializing the cart you add your extra data in the extra_data attribute of the cart object like so, http://simplecartjs.org/documentation/sendform-checkout

The beforeCheckout event callback passes in all of the data being sent to the checkout, not just the extra data. See the doc page here, http://simplecartjs.org/documentation/beforecheckout-event

You can store a nested object in there, but most likely you're going to want to serialize it so your server side code can receive it, http://api.jquery.com/jQuery.param/ . There are many different methods to do this, use whatever best suits your situation.

I have found if you can initialize simpleCart as a variable than you can easily grab its initialization properties.

var myCart = simpleCart({ 
    //settings here
});

console.log(myCart.checkout.extra_data); //view in your console
m9dfukc commented 11 years ago

Ok, just saw that "extra_data" belongs to the checkout object ... still wonder how I can dynamically get/set arbitrary customer data without using the "beforeCheckout" callback?!

m9dfukc commented 11 years ago

Ok, thanks for the fast reply ... some to work at least for a limited use. Actually I wanted to use the simpleCart Object as a "localStorage" to transfer my customer data together with the cart data between page refresh's (without using an additional localStorage Object).