How do you update the shopping cart price based on quantity?

ctsmith
Mega Sage

I have a catalog item for storage that needs to update the price based on what kind of storage and how much they are requesting.   If they choose one type of storage, it's .40 cents per GB / 12 per month (which when selected it does populate the shopping cart as .40 per month).   But, then it asks them how much they want.   So, if they say they want 10 GB, it should update the cart to 4.00 per month / 12, but it doesn't because I cannot put pricing implications on a single line of text variable.   I can't seem to find a way to do this that doesn't potentially break the shopping cart.   Many thanks for your help!

Best,

Chris

1 ACCEPTED SOLUTION

larstange
Mega Sage

Hi Chris



I did something similar as you are asking here.



If you make a reference variable, you have the option to check the "Price implications" field.


When you do that, the catalog item will look at the record that the reference variable is pointing at and look for a field named "price" or "u_price". If one is found the value here will be added to the price of the item.



That you do then is you generate a record in a custom table (where you also create a currency field named "price") when catalog item is opened and point a reference variable to this record (remeber to check the price implications box).


Your scripts must then calculate the price based on what the user selects in the different variables and update the record. The price will automatically be reflected in the cart.



See http://wiki.servicenow.com/index.php?title=Service_Catalog_Variable_Pricing#Reference


View solution in original post

9 REPLIES 9

Hi, Matt, can you give some more details on your set up?   Maybe I could help troubleshoot.   I was able to get this to work really well and have some BRs running on the backend to both set up the pricing variable and clean up the custom pricing table after the order is fulfilled. It also attaches a unique sys_id to a hidden variable on the form based on the user as well as calculate various prices per GB of storage that updates the cart onChange.  



So, you have a variable with pricing implications, and it's just not doing anything?   It doesn't update the price on the cart at all?



Thanks,


Chris


Hey Chis,



Maybe my post about the issue I am facing will provide more insight



https://community.servicenow.com/message/1123428?sr=stream&ru=94186#1123428



Thanks,


Matt


Well... my initial thought is, do you have calculated values in SN for it to come up with a number when a user inputs GB amounts?   In step 5 on your above referenced thread... Is that price per GB stored on the SN side after the call is made?   I don't make any calls out/into SN on my price calculations, but an onChange client script runs after a GB number is entered and type of storage is entered.   So, if it's say, trusted storage at .10 GB per monthy, and they choose 100 GB, it updates the shopping cart to 10.00 per month (I think my math here is right).   Something like this--here's a part of it:



var qty1 = g_form.getValue ('variables.quantity');


  var newprice1 = ((qty1 * 0.8) / 12);



  var price1 = new GlideRecord ('u_nas_quantity_price');


  price1.addQuery ('u_user_id', userID);


  price1.addQuery ('sys_id', nassys);


  price1.query();


Hi larstange

Thank you for your post!

I know it's been a while but I found this one post about being able to dynamically calculate price of a catalog item and it was a big help.

 

I wanted to share my experience since not only did I have to dynamically calculate the price but I also had to do it using a multi-line variable set.  Fun!

Hopefully you all can follow what I wrote up in the attachment.

Hi Kilo Expert, I need that requirements for this company I work for. I am a new SN admin I am not able to follow your instructions, Could you help me please. Below is a draft of the catalog item.

Danilo9_0-1690565998974.png