Skip to main content
Skip table of contents

Annex A: Calculation Formulas and Rules

STRUCTURE OF THE CALCULATION – PRICERULES.DATA

Definition of Calculation Rules

  • Each rule must consist of two lines: the rule name and the formula.

  • One rule can never have more than one formula; only the first formula will be used.

  • If you want to assign more than one formula to a rule, you have to create the rule more than once, each time with the new assigned formula.

  • A new rule always has to start with a “#“; if this is not the case, the rule will not be considered.

  • Comments have to be placed in the line preceding the rule. If any comments are placed in the same line as the rule itself, the rule will not be considered.

Correct rule labeling:

#addPagesRule

Incorrect rule labeling:

//#addPagesRule

/#addPagesRule

--#addPagesRule


Definition of Rules and Formulas

  • You can define if/then-conditions. This is done with the short “if”-command: „if ( ? : )“ Condition ? If condition true : if condition false

  • If a condition is used, it is important that you use both control characters – “?“ and “:“ – and stick to the syntax.

Example:

pp.sqMeter > 0 ? pp.sqMeter * pp.getTierPrice(pp. getPaper(‚paper_sq_rn‘), pp.sqMeter * pp.getQty() * (pp. getPages(‚page_number‘)/2) ) * (pp.getPages(‚page_number‘)/2) : pp.getPaper(‚paper_sq_rn‘) * (pp.getPages(‚page_number‘)/2)

Condition: pp.sqMeter > 0

Value if true: pp.sqMeter * pp.getTierPrice(pp.getPaper(‚paper_ sq_rn‘), pp.sqMeter * pp.getQty() * (pp.getPages(‚page_ number‘)/2) ) * (pp.getPages(‚page_number‘)/2)

Value if false: pp.getPaper(‚paper_sq_rn‘) * (pp.getPages(‚page_ number‘)/2)


In this example, the square meter shall be multiplied with the other values. Therefore we need to verify that the calculated square meter – pp.sqMeter – is more than 0. If this is the case, we add it to the formula. If not, it gets ignored.

Rule Names, Functions and Variables

There are a variety of predefined rules. These rules are:

  • #sqmSetupRule

  • #runningPriceRule

  • #sqmPriceRule

  • #priceForAllPageOptionsRule

  • #totalPriceRule

  • #adjustPriceRule

Furthermore, there are some dynamic rules, for example:

  • #addPagesRule

  • #addPaperRule

There is one rule defined in this form for each product part option. The structure always looks like this: #addYourproductpartcodeRule. The first letter of the product part option always has to be a capital letter. Additional product part options can be integrated in the calculation in the same manner.

Static Functions

  • pp.getTierPrice This function has two parameters: a set of prices and quantities as well as the quantity. The structure in the input field in backend should look like this: 100,50;200,25;500,10;

  • pp.getQty() Returns the current quantity

Dynamic Functions

  • pp.getPages, pp.getPaper, pp.getBook_binding etc. The structure of a dynamic rule looks like this: pp.getYourProductPartOptionCode The first letter of the product part option has to be a capital letter. The function contains a parameter which allows access to the contents of the attributes.

Example:

pp.getFormat(‚format_setup_price‘) , pp.getPaper(‚paper_ p100kg‘) , pp.getOptions(‚options_price_adjustment_second‘)

Static Variables

  • price.adjustPrice This price is calculated in the rule #totalPriceRule. It‘s the total price, which can be changed freely.

  • price.priceForAllPageOptions In this variable, the calculated price derives from the rule: #priceForAllPageOptionsRule.

  • price.runningPrice The value of this variable derives from the rule #runningPriceRule.

  • pp.sqMeter contains the square meters of the selected format or custom format.

  • pp.sqmSetup Value calculated from the rule #sqmSetupRule.

Dynamic Variables

  • price.priceForPages, price.priceForPaper, price. priceForBook_binding etc. These values are calculated in the rules #addPagesRule, #addPaperRule, #addBook_bindingRule etc. The value of a new rule can be picked up with price. priceForYourproductpartcode.


Errors and Log File

If a formula is not defined correctly, for example because a bracket is missing, it will produce an error, and the calculation will return a 0. Errors are logged and can be viewed in a separate file. The file is located under:

var/log/newPriceCalculation.log

STRUCTURE OF THE CALCULATION – ADJUSTPRICERULES.DATA

The file AdjustPriceRules.data extends the above file PriceRules.data and follows the same rules. The only reason they are separated is to enable maintenance of calculation of product part options and product options independently of one another and provide the best possible overview.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.