Manages ecommerce pricing rules: tiered pricing, promotional discounts, checkout rules and per-store shipping and tax configuration for a store's products. Rules are loaded from CSV and XML settings files stored under WEB-INF in the website's live branch, and applyRules combines the best-matching tier and promotional rules to work out a purchaser's adjusted price for a product. Registered with the ecommerce app as the "pricingRulesService" service and used directly by PriceManager and CartManager when pricing a sale.

Group: Managers


Properties

PropertyReturnsDescription
rulesPricingRulesSetDeprecated, use rules(store) instead. Looks up the current website from the request context and returns its pricing rules, or null if the current root folder is not a website or has no ecommerce store.

Methods

getRules() · rules(ECommerceStore store) · rules(ECommerceStore store, WebsiteRootFolder wrf) · saveRules(String storeName, List<PricingRule> list, Website website, Profile curUser) · savePricingConfig(String storeName, PricingConfiguration config, Website website, Profile currentUser) · saveCheckoutRules(String storeName, CheckoutRules checkoutRules, Website website, Profile currentUser) · parseRules(String text) · applyRules(BaseEntity purchaser, BaseEntity vendor, ECommerceStore store, Product product, ProductSku sku, BigDecimal listPrice, BigDecimal quantity, BigDecimal totalSale, Map<String,String> customFieldsMap, Set<Reward> activatedPromos, List<String> rulesNarrative) · findMatching(PricingRulesSet ruleSet, Set<Reward> activatedPromos, Product product, ProductSku sku, BaseEntity purchaser, BigDecimal quantity, BigDecimal totalSale, BaseEntity vendor, Map<String,String> customFieldsMap, Organisation adminOrg) · applyRule(PricingRule rule, BigDecimal listPrice, BaseEntity purchaser, Product product, BigDecimal quantity) · calcTax(BigDecimal finalPriceExTax, ProductInEComStore productInStoreList, ISale sale) · taxRate(BigDecimal adjustedPriceExTax, ProductInEComStore productInStore, ISale sale)

getRules()

Returns: PricingRulesSet

Deprecated, use rules(store) instead. Looks up the current website from the request context and returns its pricing rules, or null if the current root folder is not a website or has no ecommerce store.

rules(ECommerceStore store)

Returns: PricingRulesSet

Returns the pricing rules configured for the given ecommerce store, combining tiered pricing, promotional availability, checkout rules and shipping/tax provider settings. Returns null rather than an empty rule set when the store is null or its website root folder cannot be resolved.

ParameterDescription
storethe ecommerce store to find pricing rules for

rules(ECommerceStore store, WebsiteRootFolder wrf)

Returns: PricingRulesSet

Returns the pricing rules configured for the given store, looking them up from the website settings attached to the supplied root folder. Never returns null: falls back to an empty pricing rules set when the store has no saved settings.

ParameterDescription
storethe ecommerce store to find pricing rules for
wrfthe website root folder the store's settings are read from

saveRules(String storeName, List<PricingRule> list, Website website, Profile curUser)

Returns: void

Serialises the given pricing rules to CSV and writes them to the store's pricing rules file under WEB-INF in the website's live branch, creating the file if it does not already exist.

ParameterDescription
storeNamethe name of the ecommerce store the rules belong to
listthe pricing rules to save
websitethe website whose live branch the rules file is written to
curUserthe profile the change is attributed to when saving the data session

savePricingConfig(String storeName, PricingConfiguration config, Website website, Profile currentUser)

Returns: void

Serialises the given pricing configuration (shipping and tax provider settings) to XML and writes it to the store's settings file under WEB-INF in the website's live branch, creating the file if it does not already exist.

ParameterDescription
storeNamethe name of the ecommerce store the configuration belongs to
configthe pricing configuration to save
websitethe website whose live branch the settings file is written to
currentUserthe profile the change is attributed to when saving the data session

saveCheckoutRules(String storeName, CheckoutRules checkoutRules, Website website, Profile currentUser)

Returns: void

Serialises the given checkout rules to XML and writes them to the store's checkout rules file under WEB-INF in the website's live branch, creating the file if it does not already exist.

ParameterDescription
storeNamethe name of the ecommerce store the checkout rules belong to
checkoutRulesthe checkout rules to save
websitethe website whose live branch the checkout rules file is written to
currentUserthe profile the change is attributed to when saving the data session

parseRules(String text)

Returns: List<PricingRule>

Parses pricing rules from CSV text, one PricingRule per non-blank row. Column order follows the format written by the matching save/export logic: promotion name, user id, group name, org id, org type, min/max quantity, category, brand, base product code, mvel expression, add/mult/fixed value, notes, min/max total sale, custom fields and vendor org type.

ParameterDescription
textthe CSV text to parse

applyRules(BaseEntity purchaser, BaseEntity vendor, ECommerceStore store, Product product, ProductSku sku, BigDecimal listPrice, BigDecimal quantity, BigDecimal totalSale, Map<String,String> customFieldsMap, Set<Reward> activatedPromos, List<String> rulesNarrative)

Returns: AdjustedPrices

Works out the adjusted price for a product by finding the best-matching tier and promotional pricing rules for the store and applying them in turn: a tier rule is applied to the ex-tax unit price and multiplied by quantity, then a promotional rule (if any) is applied to the resulting inc-tax cost to give the final promotional cost. Human-readable descriptions of each step applied are appended to rulesNarrative.

ParameterDescription
purchaserthe profile or organisation buying the product
vendorthe profile or organisation selling the product, used to match vendor org type rules
storethe ecommerce store the pricing rules are read from
productthe product being priced
skuthe specific product sku being priced, may be null
listPricethe ex-tax list unit price before any rules are applied
quantitythe quantity being purchased
totalSalethe running total of the sale, used to match min/max total sale rules
customFieldsMapcustom field values supplied with the purchase, used to match custom field rules
activatedPromosthe rewards or promotions currently activated for the purchaser
rulesNarrativea list that human-readable descriptions of the rules applied are appended to

findMatching(PricingRulesSet ruleSet, Set<Reward> activatedPromos, Product product, ProductSku sku, BaseEntity purchaser, BigDecimal quantity, BigDecimal totalSale, BaseEntity vendor, Map<String,String> customFieldsMap, Organisation adminOrg)

Returns: Set<PricingRule>

Finds the pricing rules in the given rule set whose match criteria (product, sku, quantity, org, group, custom fields and activated promotions) are satisfied for the given purchaser and product. Used by applyRules to narrow the store's rule set down to the rules that actually apply to the current sale.

ParameterDescription
ruleSetthe store's pricing rules to search, may be null
activatedPromosthe rewards or promotions currently activated for the purchaser
productthe product being priced
skuthe specific product sku being priced, optional
purchaserthe profile or organisation buying the product, optional
quantitythe quantity being purchased
totalSalethe running total of the sale, used to match min/max total sale rules
vendorthe profile or organisation selling the product, used to match vendor org type rules
customFieldsMapcustom field values supplied with the purchase, used to match custom field rules
adminOrgthe admin organisation the purchaser's group and org type memberships are resolved within

applyRule(PricingRule rule, BigDecimal listPrice, BaseEntity purchaser, Product product, BigDecimal quantity)

Returns: BigDecimal

Applies a single pricing rule to a list price: a fixed value replaces the price, an add value is added, a multiplier is applied, and finally, if the rule has an mvel expression, that expression is evaluated (with the purchaser, product, adjusted price and quantity in scope) and its result becomes the final price.

ParameterDescription
rulethe pricing rule to apply
listPricethe price to apply the rule to
purchaserthe profile or organisation the price is being calculated for, available to the rule's mvel expression
productthe product being priced, available to the rule's mvel expression
quantitythe quantity being purchased, defaults to one if null, available to the rule's mvel expression

calcTax(BigDecimal finalPriceExTax, ProductInEComStore productInStoreList, ISale sale)

Returns: BigDecimal

Calculates the tax amount for a price by multiplying it by the effective tax rate for the product in its store, as returned by taxRate.

ParameterDescription
finalPriceExTaxthe ex-tax price to calculate tax on
productInStoreListthe product in its store, used to resolve the applicable tax rate
salethe sale the tax is being calculated for, passed through to any configured tax calc provider

taxRate(BigDecimal adjustedPriceExTax, ProductInEComStore productInStore, ISale sale)

Returns: BigDecimal

Works out the tax rate to apply to a product in a store. Tries each configured tax calc provider for the store in turn and uses the first non-null rate returned, falling back to the product's effective GST rate (or zero) if no provider applies.

ParameterDescription
adjustedPriceExTaxthe ex-tax price the tax rate will be applied to
productInStorethe product in its store, used to resolve configured tax calc providers and the fallback GST rate
salethe sale the tax rate is being calculated for, passed through to any configured tax calc provider
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.