Skip to main content
bryans16389082
Inspiring
August 27, 2022
Answered

Script for calculating Quantity Discounts based on quantity of products

  • August 27, 2022
  • 2 replies
  • 2069 views

I have created an order form for our products and got through most of the calculations but I am not quite smart enough to get my last one.

 

The way my form is setup I have products priced each and multiplied by quantity per line.

I need a discount script based on the Quantity so our prices are full price 1-20, $5 off each 21-50, $10 off each 51-100, $15 off each 100+ 

 

Is there a simple solution to make this happen?

 

Thanks in advance for any help you can offer.

This topic has been closed for replies.
Correct answer bryans16389082

Still not quite what I am looking for so I have multiple products in a drop menu and they are all various prices they calculate with the quantity to get the line total so when you use the QTY*Total this does not work to get the correct discount I want the discount only based on the quantity and when there is 20 I want them all regular price once they hit 21 I want a $5 discount for all 21+ Same With 51 I want all 51+ to have a $10 discount..? etc


Got it now this is the code that worked for my purpose Quantity only discounts.

 

var qty = Number(this.getField("Quantity").valueAsString);
var total = 0;
if(qty>100)
total = qty*(-15);
else if(qty>50)
total = qty*(-10);
else if(qty>20)
total = qty*(-5);
event.value = total;

 

Thanks for the help!

2 replies

try67
Community Expert
Community Expert
August 27, 2022

You can use something like this to achieve it:

 

var qty = Number(this.getField("Qty1").valueAsString);
var price = Number(this.getField("Price1").valueAsString);
var total = qty*price;
var discount = 0;
while (qty>100) {discount+=15; qty--};
while (qty>50) {discount+=10; qty--};
while (qty>20) {discount+=5; qty--};
event.value = total-discount;
bryans16389082
Inspiring
August 27, 2022

This is working with my form only thing that needs to change is I need it to give off  $100 at 21+ then the $5 so the previous items get the discount they added as well.  Thanks for the help!

 

var qty = Number(this.getField("Quantity").valueAsString);
var price = Number(this.getField("Line Total").valueAsString);
var total = 0;
var discount = 0;
while (qty>100) {discount+=15; qty--};
while (qty>50) {discount+=10; qty--};
while (qty>20) {discount+=5; qty--};
event.value = total-discount;

bryans16389082
Inspiring
August 27, 2022

I am also using multiple quantities boxes and need them to all work together with the quantity discounts.

bryans16389082
Inspiring
August 27, 2022

Some of all quantities then $5 off per tier level any one out there any help?