I'm just starting out with backbone.js and trying to wrap my head around the modeling concepts. I want to use backbone js to create a shopping cart app, interfacing with a 3rd party REST api (not rails, can't modify).
This is the JSON response example for GET cart contents:
{
"_v" : "12.3",
"currency" : "USD",
"product_sub_total" : 96.00,
"product_total" : 86.00,
"shipping_total" : null,
"tax_total" : null,
"order_total" : null,
"product_items" :
[
{
"product_id" : "123",
"item_text" : "Product foo",
"quantity" : 2.00,
"product_name" : "foo",
"base_price" : 30.00,
"price" : 60.00
},
{
"product_id" : "456",
"item_text" : "Product foo",
"quantity" : 1.00,
"product_name" : "bar",
"base_price" : 40.00,
"price" : 40.00,
"price_adjustments" :
[
{
"promotion_id" : "10% off",
"promotion_link" : "http://example.com/dw/shop/v12_3/promotions/10_percent_off",
"item_text" : "10% off",
"price" : -4.00
}
]
}
],
"order_price_adjustments" :
[
{
"promotion_id" : "10$ off",
"promotion_link" : "http://example.com/dw/shop/v12_3/promotions/10_bugs_off",
"item_text" : "10$ off",
"price" : -10.00
}
]
}
Looking at this JSON data, there are aggregate pieces of data like "product_total", and "shipping_total", and there are lists contained within like "product_items" and "order_price_adjustments". Even individual "product_items" can also have nested list of "price_adjustments".
How can I model this shopping cart in backbone.js? Should I create a model for every hash that I see ("product_item", "price_adjustment") and then model a collection of those models and then make a basket model that contains those collections as well as aggregate datas? I'm not sure how to approach this...