I am developing an android application which is linked with Woo-commerce. I hit API on Postman it added the product and gave total item in cart but when I hit same API with same parameter ,I am getting 0 item in cart. I am adding product through mobile app. I am totally confused. I am using volley library. So I thought it's happening because of cache, so I tried clearing the cache but got same response in Json. Help me. Do I need to integrate Woo-commerce in android. If yes then How ?
[Postman response total item in cart][1]
JSON response on android studio
Add to cart :--
{"status":1,"item_key":"c6a01432c8138d46ba39957a8250e027","cart_content":{"products":[{"id":3129,"title":"Surya Toast-O Toaster","qty":1,"price":"1195","regular_price":"1495","sale_price":"1195","image":"http://www.electrisia.com/wp-content/uploads/2015/11/Surya-10-Sizzle-10-L-SDL647886232-1-a142d16-200x150.jpg"}],"count":1,"line_count":1},"msg":"Product added to cart successfully"}
Total item in cart response {"status":1,"Total Items in a cart":0}
I know woo-commerce managing a kind of cache for each user on website like in postman man every time when i hit add to cart API it automatically add item on my previous cart but in mobile it doesn't. every time i click add to cart i get 0 on total item in cart.
code of total item in cart :-
StringRequest request = new StringRequest(Request.Method.GET,TotalItemCart,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("Response",response);
ProgressUtils.cancelProgressDialog();
try {
JSONObject object = new JSONObject(response);
/* if(object.has("count"))
{
cartItemCount = object.getString("count");
tv.setText(cartItemCount);
}*/
if(object.has("status")) {
if (object.getInt("status") == 1) {
if(object.has("Total Items in a cart"))
{
cartItemCount = object.getString("Total Items in a cart");
tv.setText(cartItemCount);
}
}else {
Toast.makeText(ItemDescriptionActivity.this,"failed to add item",Toast.LENGTH_SHORT).show();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
ProgressUtils.cancelProgressDialog();
Toast.makeText(ItemDescriptionActivity.this, "Cart not updated", Toast.LENGTH_SHORT).show();
}
});
queue.add(request);
Add to cart API response postman
Add to cart code
ProgressUtils.showProgressDialog(ItemDescriptionActivity.this);
StringRequest request = new StringRequest(Request.Method.POST,AppConstant.AddToCart,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("Response",response);
ProgressUtils.cancelProgressDialog();
if(response != null)
{
try {
JSONObject responseOBJ = new JSONObject(response);
if(responseOBJ.has("status"))
{
if(responseOBJ.getInt("status")==1)
{
Toast.makeText(ItemDescriptionActivity.this,"Item added successfully",Toast.LENGTH_SHORT).show();
ItemCartCount();
}else {
if(responseOBJ.has("msg"))
{
Toast.makeText(ItemDescriptionActivity.this,""+responseOBJ.getString("msg"),Toast.LENGTH_SHORT).show();
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
ProgressUtils.cancelProgressDialog();
Toast.makeText(ItemDescriptionActivity.this, "Someting went wrong...", Toast.LENGTH_SHORT).show();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params = new HashMap<String, String>();
params.put("product_id", String.valueOf(AppConstant.Product_ID));
params.put("qty","1");
params.put("secret_key",sec_key);
return params;
}
//no semicolon or coma
};
queue.add(request);