0
votes

I am struggling with the sapui5 local storage lib and the shopping cart demo app which uses this function (https://openui5.hana.ondemand.com/test-resources/sap/m/demokit/cart/webapp/index.html).

I am making an easy example which puts an article to the local storage. when you continue shopping and add another article to the basket it should be also be put to the local storage. but what I get is, that only the last item is in the storage. any hints on this? I am using some parts of the sap demo but it does not work for me.

here is the coding which puts the item to the local storage.

I tried it the way like in the demo. coding can be found here

var sProductKey = oData.productkey;
var sQuantity = this.byId("inpQuantity").getValue();

var oMySc = [{                  // this is the current item
            productKey: sProductKey,
            quantity: sQuantity
        }];


// in the collectionEntries object, the old items are getting loaded
var oCollectionEntries = [];
var oCartModel = this.getOwnerComponent().getModel("cartProducts");
oCollectionEntries = Object.assign({}, oCartModel.getData()["cartEntries"]);


var oCartEntry = Object.assign({}, oMySc);
oCollectionEntries[oCartEntry] = oCartEntry;

//oCart Model refers to the local Storage functions
oCartModel.setProperty("/cartEntries", Object.assign({}, oCollectionEntries));
oCartModel.refresh(true);
1

1 Answers

0
votes

Cant you just try to do something like this?

oCollectionEntries.push(oCartEntry);