Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

When the price of one product depends on the price of another product within the same price list (or LPG) then you need to calculate the price list in several rounds /(= passes).

From the technical perspective:

...

  • 1st pass – Calculation logic is executed for all lines:
    1. Lines, which can be priced/calculated right away are calculated.
    2. Lines, which need to wait for a price of another product, will mark themselves have to be marked as "dirty" and scheduled for the calculation in the next pass.
  • 2nd pass – Calculation logic is executed only for lines marked as "dirty":
    1. Lines, which can be already priced/calculated are calculated.
    2. Lines, which still need to wait for a price of another product (i.e. the product, they refer to, is still not calculated), will mark themselves as "dirty".
  • 3rd pass – If there are still some lines marked as "dirty" then the system will repeat the steps of the 2nd pass. By default the server is set to do only 2 passes.

(info) The current item is only dirty-recalculated when it is the only dirty item. If there are more dirty items resulting from the initial calculation, all dirty items including the initial item are calculated in the same background process. 


Code Block
languagegroovy
titleConceptual Example - only for 2-pass calculation
def priceresultPrice

if (productDoesNotDependOnAnotherisLeader()) {

    /* result price ofdoesn't thehave product does not depend dependency on another product */
  /* so we can => calculate the price right away */
  price  resultPrice = calculatedPricecalculateLeaderPrice()

} else {

    /* result price of the product is derived from the price of the other (= leading) product */
    if (api.getIterationNumber() == 0) {

        /* if thisin the 1st pass the leader product is not firstyet passcalculated, so thenmark wethis needitem to waitbe calculated forin the related product to be calculated */ next pass */
        api.markItemDirty()

        /* do not calculate remaining elements for a better performance */
        api.markItemDirtyabortCalculation()

    } else {

        /* thisin isthe already second2nd pass, so we expect the otherleader product tois be calculated already */
    relatedProductPrice    def leaderPrice = api.currentContext(skuOfTheRelatedProductleaderSku)?.ResultPrice

        priceresultPrice = doAdjustmentsOfThePricecalculateFollowerPrice(relatedProductPriceleaderPrice)

    }
}

return priceresultPrice

Useful Functions and Properties

  • api.getIterationNumber() – Returns the number of passes the list has been through. (Initial 1st pass = 0, second pass = 1, and so on). It replaces api.isSecondPass() function which is now deprecated.
  • api.currentContext(otherSku) – Reads the results from another product (within the same pricelist/LPGPrice List or Live Price Grid).
  • api.markItemDirty() – Sets the current line item as dirty (when we need some other product to be calculated first).

You can also suppress autoApprove when an item is dirty by setting an advanced config property on a partition:

Code Block
skipAutoApproveOnDirtyPGI = true

...