Am using jquery shopping cart http://plugins.jquery.com/project/smartcart2
Can anyone help me in implementing onAdded, onRemoved, onUpdated methods in order to make Ajax call to maintain session on the server side.
I make the Ajax request on the server whenever an object is added/removed/updated and get the data back in JSON format. I update the qty like obj.attr("qty", eval(msg)[1]);
with the updates from server.
However, if i hit refresh or the table data is repopulated the cart items are no longer there. So, the question really is how to populate the data from session so that the product would still remain in the shopping cart upon refresh etc.
$( #SmartCart ).smartCart({
onAdded: function(pObj,quantity){ cartAdded(pObj,quantity);},
onRemoved: function(pObj){ cartRemoved(pObj);},
onUpdated: function(pObj,quantity){ cartUpdated(pObj,quantity); },
});
function cartAdded(obj,qty){
var product_id = obj.attr("pid");
var quantity = qty;
// Ajax calls for adding product to cart
function(pObj,quantity){
cartAdded(pObj,quantity);}
}
function cartRemoved(obj){
var product_id = obj.attr("pid");
// Ajax call for removing product from cart
}
function cartUpdated(obj,qty){
var product_id = obj.attr("pid");
var quantity = qty;
// Ajax call for updating product on cart
}
function cartAdded(obj,qty){
var partNum = obj.attr("partNumber");
var quantity = qty;
$.ajax({
type: POST ,
url: "json/sessionManager",
data : "partNum=" + partNum + "&qty=" + quantity,
dataType: "text/json",
success: function(msg){
obj.attr("qty", msg[1]);
},
error: function(httpRequest, textStatus, errorThrown) {
alert("status=" + textStatus + ",error=" + errorThrown);
}
});
}
I would highly appreciate recommendations around the same.