Skip to Content
author's profile photo Former Member
Former Member

In shopping cart project cart items are removed when i refresh the page


I am doing shopping cart project when i add the products to cart the products are removed when i refresh the page.But, cart items should never remove when i refresh the page, if anybody knows please comment your answers.

My code is like this

createContent: function()


var oView = sap.ui.view({

id: "app",

viewName: "shoppingcart2.App",

type: "JS",

viewData: {component: this}


var oModel = new sap.ui.model.odata.ODataModel("/sap/opu/odata/SAP/ZPROJECT_SHOPPING_CART_SRV",true,"username", "password"); sap.ui.getCore().setModel(oModel,'products'); oView.setModel(oModel, 'products');

var data = {

items: []


var oCartModel = new sap.ui.model.json.JSONModel(data); oView.setModel(oCartModel,'cart');

addToCart: function(e,obj)

{ var model = obj.getModel("model2");

var data = model.oData;

var cart = obj.getModel('cart').getData();


var exist = false;

$.each(cart.items, function(i, obj)


if(obj.Pid == data.Pid){

exist = true, cart.items[i].Pquan += 1; }




cart.items.push({ Pid: data.Pid, Pname: data.Pname, Pquan: 1,

Pfilename: data.Pfilename, Pprice:data.Pprice, Pdesc:data.Pdesc



obj.getModel('cart').setData(cart);'Item added in cart');


Add comment
10|10000 characters needed characters exceeded

1 Answer

  • Posted on Feb 21, 2017 at 06:01 PM

    There is no persistent data storage in your code. Are you storing the newly added item to database?

    After refresh the code tries to retrieve data from JSON model which is created new after every refresh.

    Save the data to a DB or local browser storage

    Add comment
    10|10000 characters needed characters exceeded