cancel
Showing results for 
Search instead for 
Did you mean: 

Updating an item counter for a Cart button

mkoch_wu
Participant
0 Kudos
1,484

Hi,

I am implementing a cart function into my UI5 app to collect a collection of items for further processing. My cart works fine as a feature in my Master-Detail app.

One thing I'd like to add is a counter next to the cart button to inform the user how many items currently are in the cart. My Gateway service happily returns the correct value when I use the $count option. So far, so good.

What I'm struggling with is the

  1. the correct location to update the counter next to the button
  2. retrieving the oData response

re 1: I decided to retrieve the counter within the onBeforeRendering method. Although I am happy to listen to any advice here.

re 2: I am using the code below.

onBeforeRendering: function() {
	var oCountModel = new sap.ui.model.odata.v2.ODataModel("<oData GW service>");

	oCountModel.read("/cartSet/$count", {
		method: "GET",
		async:false,
		success: function(data) {
			var response = (JSON.stringify(data));
				},
		error: function() {
				}
	});
},

The above code call the service synchronous, but doesn't return the service response ("data is undefined"). However, I can see the response later in the Network tab in Chrome.

So basically, the service works and is called, but for some reason I can't seem to get the resulting response.

Any ideas/hints where I am going wrong with this?

View Entire Topic
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos

Have you tried transaction /n/iwfnd/traces to find out how the http request looks like that is received by the SAP Gateway system?

Regards,

Andre