How to get Shopping Cart Quantity in Catalog client script ?

tezen
Mega Expert

Hi All,

In Dev Helsinski....

Trying to get the value of shopping cart Quantity on a catalog client script.   Using price from UI macro "sc_order_item_subtotal", id = price_label_span but not able to get the quantity

find_real_file.png

Thanks

Tez

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Use thin in the client script to get the quantity



$('quantity').value


View solution in original post

8 REPLIES 8

hi, did you  get a solution for this ?

rohit2926
Kilo Contributor

Hi, I need to get price and quantity in catalog client script.

can you tell me how you achieved it using UI macro "sc_order_item_subtotal", id = price_label_span ????????

swapna25
Tera Contributor

Thank you Abhinay.

I tried $('quantity').value but my Chrome failed with "TypeError : $ is not a function".

I even added a system property glide.script.block.client.globals=false. It did not help either. 

Finally, I used a GlideAjax and got what I wanted. 

CART item values are stored in sc_cart_item on server. You can write a GlideAjax and get the number of items added in cart.

 

-------

Client Script:

var user = g_user.userID;
var ga = new GlideAjax('GetCartQuantity');
ga.addParam('sysparm_name','getCartQuantity');
ga.addParam('sysparm_userid',user);
ga.getXML(getcartquantity);

 

function getcartquantity(response){
var cart_quantity = response.responseXML.documentElement.getAttribute("answer");

alert(cart_quantity);

}

----------

Server side ( you need to add a script include named GetCartQuantity ). Make sure it is client callable.

var GetCartQuantity = Class.create();
GetCartQuantity.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCartQuantity:function() {

var dbg=true;
var userid = this.getParameter('sysparm_userid');
var sc = new GlideRecord('sc_cart');
sc.addQuery('name','DEFAULT');
sc.addQuery('user',userid);
sc.query();

while(sc.next()){
var cc= new GlideRecord('sc_cart_item');
cc.addQuery('item_name','SYS****ID***OF ** CATALOG ITEM');
cc.addQuery('cart',sc.sys_id);
cc.query();

if(cc.next()){
return cc.quantity;
}

}
}
});

 

-------------------

 

shaik ismail
Tera Contributor

Hello Swapna,


I tried your code , but still i am getting the Quantity as null. Also I tried to look at the table - sc_cart_item, but there is no data available. 

I am working on Madrid version.

Please advice me.

 

Thanks

Ismail