Calculation Type: LevelFormula__c Field Specification

Level Formula allows specifying a formula for calculating product quantity, based on which the discount will be calculated.

Level Formula is also available for freebies. For more information, refer to Freebie Condition: LevelFormula__c Field Specification.

Examples

The formula performs calculations in fields based on the object set in the Level Based On field.

Example of a complex calculation of quantity using addition and multiplication on several levels:

{
    "operator": "sum",
    "items": [3,
        {
            "operator": "multi",
            "items": [
                "orders__QuantityFromPreviousOrders__c",
                "$.quantity"
            ]
        }
    ]
}

Example of a calculation with addition and roundTo:

{
    "operator": "sum",
    "roundTo"  : 2
    "items": [
        "orders__QuantityFromPreviousOrders__c",
        "$.quantity"
    ]
}

Example of a calculation with division and cutDecimalsTo:

{
    "operator": "divide",
    "cutDecimalsTo"  : 0
    "items": [
        "$.totalPrice",
        300
    ]
}

Example of a calculation with multiplication and minus:

{
    "operator": "multi",
    "items": [
        "$.quantity",
        "-orders__QuantityFromPreviousOrders__c",
    ]
}

JSON Key Description

Key Type Required Comment

cutDecimalsTo

Number

No

The optional operator that truncates the number of the decimal places on the resulting value after the operations with items.

It can be used in pair with roundTo after rounding.

items

Array

Yes

Items to be used in calculations.

  • Fields on following objects:

    • Order Line item

    • Delivery Line Item

  • A constant value.

  • Fields on related objects, for example, ProductId__r.Weight__c.

  • The following fields specified in the CT Orders settings in the format:

    • $.listPrice

    • $.quantity

    • $.unitPrice

    • $.totalPrice

    • $.totalDiscount

operator

Enum

Yes

The arithmetic operation:

  • sum is addition

  • multi is multiplication. Multiplication by 0 will result in 0.

  • minus is substraction.

    It is possible to use the minus sign, for example, -$.quantity. The minus sign is considered in the calculations.
  • divide is division. Division by 0 will result in 0.

roundTo

Number

No

The optional and rounds the number of decimals on the resulting value after the operations with items.

It can be used in pair with cutDecimalsTo before truncating to the required number of decimal places.

``