Expand my Community achievements bar.

Price Breaks

Avatar

Level 2

I'm making an order form, with a list of about 15 different products, and I need to be able to calculate the subtotal of an order based on what product was selected.

I have a drop-down list that has all of the products listed, and I can calculate the subtotal of the order based on the number of products ordered.

All I need to do now is add a price break.  For example:

Qty 1 x (Product A) = $10.00/unit

Qty 5 x (Product A) = $8.00/unit

...and so on.

I have no idea how to change the price based on the quantity.

Any advice?

4 Replies

Avatar

Level 7

I handle this sort of thing with a hidden table containg the data and then devise a script to look up the appropriate price in the hidden table. You can also script your dropdown box to get the item descriptions from the hidden table for your dropdown box as well. This means there is only one place to make changes.

I don't know if the price breaks are the same quantities for each item. (e.g. breaks at 5, 10, 25 etc) for all the items. It makes it easier if it is. However, with a little thought you can devise a lookup method that will accomodate different breaks for different items.

Avatar

Level 2

Luckily, the price breaks are the same quantities for each item, so adding a table would be easy.

(I'm a bit of a newbie though--I just started working with LiveCycle last friday--I'm not entirely sure how to do what you just suggested...)

Would adding a hidden table simply mean that I add the table to the form, then go to the Object tab >> Field tab >> and change the presence to Hidden?

Avatar

Level 7

Yes, or put the table in a subform that you hide.

Also, name all the cells "Cell" and all the rows "Row".Then, you end up acomplishing a multi-dimensional array, of sorts.

Your dropdown box can be filled using something like (this example is in formcalc place on the preOpen event)

$.clearItems

var desc = ""

for i=1 upto 15 step 1 do

     if(hasValue(hiddenSubform.priceTable.Row[i].Cell[0]))then       //checks to see if a

          desc=hiddenSubform.priceTable.Row[i].Cell[0]                    //description is available

          $.addItem(desc,i)                                                                 //assigns the description

          continue                                                                              //to the variable adds the

     else                                                                                          // description and the

          continue                                                                              // row index to the

     endif                                                                                          //dropdown box

endfor

Then when they choose an item, the dropdown box's value is the "index" for your priceTable.Row[]

So the script on you price for your "each" field using the calculate event could look like (if there were 5 price levels)

var priceIndex = itemDropdown                                                          // the item selected

var quant = quantField                                                                        //the quantity inputted

var priceEach = hiddenSubform.priceTable.Row[priceIndex].Cell[1])       //the default price

for i=2 upto 5 step 1 do

     if (quant le hiddenSubform.priceTable.Row[0].Cell[i])then                    //looks at the Row[0]

          priceEach = hiddenSubform.priceTable.Row[priceIndex].Cell[i]      //which is the table

      endif                                                                                                     //header. compares

endfor                                                                            //to the quant input and changes price

$ = priceEach                         //displays the correct price

One more thing--enter values in the priceTable as "default" values  (object panel>default value)

Really, this is just to give you an idea of how to fill your dropdown with the descriptions and indexes and then use the selected item as an index to lookup values. There are various ways to implement this--you may instead choose to fill a second dropdown box with price choices--once again taken from the hidden table.

Changing and adding items is all done to the table--you could build it for the future and put 25 rows. Since the script checks to see if a description exists, you can even have empty rows if you happen to remove an item.