How to get Cart item price and quantity onLoad of the catalog item form ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2019 06:52 PM
Can anyone help me to get price and quantity of the service portal cart without adding item to the cart and getting these values using onload catalog client script of the catalog item form?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2025 05:58 PM
Hmm... replying many years later... well, hopefully this will help someone.
There is a way to get the quantity and price of a catalog item from variables, but it's a bit convoluted.
The first step is to create a custom table to hold the prices. For my purpose, I created a table with fields for Product Model, Price (must be named price or u_price, and must be Currency type), and Date (of last purchase).
So, my catalog item would initially have a variable for Product Model. There is also a variable that is a reference to my custom table. For that variable, the 'Pricing Implications' checkbox (hidden, so a little bit of a pain to set) must be checked.
When the Model is selected, it checks for a record in my custom table (I called it price history). If found, it sets my price variable and makes it display. If not found, it exposes another variable instead, where the price can be set. Setting the price in that second variable creates (via an onChange client script calling a script include. Also, remember to prepend 'USD;' to your price, since it is a Currency field) a price history record, sets that price history variable, hides itself and exposes the price history variable. This is enough to get the shopping cart to show the correct price.
A last touch is to have the Purchase Order Line Item, via a BR, when 'Received', update the price history record with the latest price and purchase date.
The quantity is simple, but not where you would expect it. I couldn't find a way to make it work with a BR on sc_cart_item, but I could do it with the sc_item_option. Set the condition for Cart Item to be not empty, and for Question (item_option_new) to be your quantity variable. Have the script query for the cart item record, and update the quantity to be current.value (.getValue()? Doing this from memory; can't check from here).
Ahh... I should also point out that I'm working from a Catalog Item with a price of zero. If your price is non-zero, the price from that variable reference will be added to the Catalog Item price. Coder beware. 🙂
Sorry that's so high-level; can't cut and paste my code. But I hope it's still useful.