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
| Property | Returns | Description |
|---|---|---|
| rules | 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. |
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.
| Parameter | Description |
|---|---|
store | the 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.
| Parameter | Description |
|---|---|
store | the ecommerce store to find pricing rules for |
wrf | the 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.
| Parameter | Description |
|---|---|
storeName | the name of the ecommerce store the rules belong to |
list | the pricing rules to save |
website | the website whose live branch the rules file is written to |
curUser | the 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.
| Parameter | Description |
|---|---|
storeName | the name of the ecommerce store the configuration belongs to |
config | the pricing configuration to save |
website | the website whose live branch the settings file is written to |
currentUser | the 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.
| Parameter | Description |
|---|---|
storeName | the name of the ecommerce store the checkout rules belong to |
checkoutRules | the checkout rules to save |
website | the website whose live branch the checkout rules file is written to |
currentUser | the 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.
| Parameter | Description |
|---|---|
text | the 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.
| Parameter | Description |
|---|---|
purchaser | the profile or organisation buying the product |
vendor | the profile or organisation selling the product, used to match vendor org type rules |
store | the ecommerce store the pricing rules are read from |
product | the product being priced |
sku | the specific product sku being priced, may be null |
listPrice | the ex-tax list unit price before any rules are applied |
quantity | the quantity being purchased |
totalSale | the running total of the sale, used to match min/max total sale rules |
customFieldsMap | custom field values supplied with the purchase, used to match custom field rules |
activatedPromos | the rewards or promotions currently activated for the purchaser |
rulesNarrative | a 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.
| Parameter | Description |
|---|---|
ruleSet | the store's pricing rules to search, may be null |
activatedPromos | the rewards or promotions currently activated for the purchaser |
product | the product being priced |
sku | the specific product sku being priced, optional |
purchaser | the profile or organisation buying the product, optional |
quantity | the quantity being purchased |
totalSale | the running total of the sale, used to match min/max total sale rules |
vendor | the profile or organisation selling the product, used to match vendor org type rules |
customFieldsMap | custom field values supplied with the purchase, used to match custom field rules |
adminOrg | the 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.
| Parameter | Description |
|---|---|
rule | the pricing rule to apply |
listPrice | the price to apply the rule to |
purchaser | the profile or organisation the price is being calculated for, available to the rule's mvel expression |
product | the product being priced, available to the rule's mvel expression |
quantity | the 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.
| Parameter | Description |
|---|---|
finalPriceExTax | the ex-tax price to calculate tax on |
productInStoreList | the product in its store, used to resolve the applicable tax rate |
sale | the 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.
| Parameter | Description |
|---|---|
adjustedPriceExTax | the ex-tax price the tax rate will be applied to |
productInStore | the product in its store, used to resolve configured tax calc providers and the fallback GST rate |
sale | the sale the tax rate is being calculated for, passed through to any configured tax calc provider |