Salesforce B2C Commerce 19.4 > B2C Commerce API > B2C Commerce Script > dw.catalog
dw.catalog
Class ProductPriceModel
Object
dw.catalog.ProductPriceModel
ProductPriceModel provides methods to access all the PriceBook information of a product. A ProductPriceModel instance is retrieved by calling Product.getPriceModel() or Product.getPriceModel(ProductOptionModel) for a specific product. The latter method will return a model which also includes the additional option prices of an option product.

When the current price of a product is accessed in the storefront via its price model, a price lookup is performed. The high-level steps of this price lookup are:

  • Get all price books applicable in the context of the current site, time, session, customer, source code.
  • Identify all prices in the applicable price books and for a requested quantity.
  • Calculate the best-price of all identified prices. The best-price is the lowest price.
In more detail:

Identify applicable price books

  • If any price books are explicitly registered in the session (see pipelet SetApplicablePriceBooks), use these price books and their direct parents for price lookup. Ignore all inactive price books, price books not valid at the current time, and price books with a currency other than the session currency.
Otherwise:
  • If a valid source code is registered with the current session, get all price books assigned to the source code and their parent price books. Ignore all inactive price books, price books not valid at the current time, and price books with a currency other than the session currency.
  • Get all price books assigned to site and their parent price books. Ignore all inactive price books, price books not valid at the current time, and price books with a currency other than the session currency.
Identify all prices:
  • Get all price definitions for the product from all applicable price books. Ignore price definitions not valid at the current time.
  • Convert any percentage price definition into a monetary amount. As the base price for this calculation, the minimum product price for the minimum order quantity of the product, including product options, is used.
  • Compare all prices and identify the lowest (= best) price.
  • Calculate best price for each defined price cut in the price table and return price table.
Variation Price Fallback:
  • If no applicable pricebooks for a variant is found, the price lookup gets the price books from the variant's master product
  • A price books is also not applicable of the price definition for the variant in the price book is not valid at the current time.

Typically, in order to do a standard price lookup, it is only necessary to call Product.getPriceModel().getPrice(). However, Commerce Cloud Digital also supports tiered prices, meaning that higher quantities receive a lower price. In this case, the merchant typically wants to display a table of price points on product detail pages. Therefore, the ProductPriceModel provides the method getPriceTable() to retrieve a table of these prices.

If a merchant wants to know not only what the price of a given product is, but what price book the price was derived from, this class provides the method getPriceInfo(). This class also provides methods to lookup product prices in specific price books by name and quantity. See getPriceBookPrice(String).

Properties
basePriceQuantity  :  Quantity  (Read Only)
The quantity for which the base price is defined. This is typically 1.0.
maxPrice  :  Money  (Read Only)
Calculates and returns the maximum price-book price of all variants (for master products) or set-products (for product sets) for base quantity 1.00. This value can be used to display a range of prices in storefront. If the product represented by this model is not a master product or product set, then this method behaves the same as getPrice(). Only online products are considered. If the "orderable products only" search preference is enabled for the current site, then only orderable products are considered. For master products, only variants with all variation attributes configured are considered.

Warning: If the product represented by this model is a master product with numerous variants, this method can be very expensive and should be avoided.

minPrice  :  Money  (Read Only)
Calculates and returns the minimum price-book price of all variants (for master products) or set-products (for product sets) for base quantity 1.00. This value can be used to display a range of prices in storefront. If the product represented by this model is not a master product or product set, then this method behaves the same as getPrice(). Only online products are considered. If the "orderable products only" search preference is enabled for the current site, then only orderable products are considered. For master products, only variants with all variation attributes configured are considered.

Warning: If the product represented by this model is a master product with numerous variants, this method can be very expensive and should be avoided.

price  :  Money  (Read Only)
The price of a product, calculated based on base price quantity 1.00. The price is returned for the currency of the current session.

The price lookup is based on the configuration of price books. It depends on various settings, such as which price books are active, or explicitly set as applicable in the current session.

If the product represented by this model is an option product, option prices will be added to the price book price if the price model was initialized with an option model.

If no price could be found, MONEY.NOT_AVAILABLE is returned.

priceInfo  :  ProductPriceInfo  (Read Only)
The price info of a product, calculated based on base price quantity 1.00. The price is returned for the currency of the current session.

This method is similar to getPrice() but instead of just returning the price value, it returns a ProductPriceInfo which contains additional information such as the PriceBook which defined the price and the percentage discount this price point represents.

If the product represented by this model is an option product, option prices will be added to the price book price if the price model was initialized with an option model.

If no price info could be found, null is returned.

priceInfos  :  Collection  (Read Only)
All the price infos of a product that could have been the basis of the storefront price, calculated based on base price quantity 1.00. This will return an empty list if getPriceInfo() would return null, and if there is only one price info in the collection it will be the same price info as getPriceInfo(). Two or more price infos indicate that there are that many price books that meet the criteria for returning the price shown in the storefront.
priceRange  :  boolean  (Read Only)
Returns true if this product is a master product (or product set) and the collection of online variants (or set products respectively) contains products of different prices.

Warning: If the product represented by this model is a master product with numerous variants, this method can be very expensive and should be avoided.

priceTable  :  ProductPriceTable  (Read Only)
The product price table object. The price table represents a map between order quantities and prices, and also provides % off information to be shown to storefront customers. The price is returned for the currency of the current session.

Usually, the product price table is printed on product detail pages in the storefront.

If the product represented by this model is an option product, option prices will be added to the price book price if the price model was initialized with an option model.

All other methods of this class are based on the information in the product price table.

Constructor Summary
This class does not have a constructor, so you cannot create it directly.
Method Summary
getBasePriceQuantity() : Quantity
Returns the quantity for which the base price is defined.
getMaxPrice() : Money
Calculates and returns the maximum price-book price of all variants (for master products) or set-products (for product sets) for base quantity 1.00.
getMaxPriceBookPrice(priceBookID : String) : Money
Calculates and returns the maximum price in a given price book of all variants (for master products) or set-products (for product sets) for base quantity 1.00.
getMinPrice() : Money
Calculates and returns the minimum price-book price of all variants (for master products) or set-products (for product sets) for base quantity 1.00.
getMinPriceBookPrice(priceBookID : String) : Money
Calculates and returns the minimum price in a given price book of all variants (for master products) or set-products (for product sets) for base quantity 1.00.
getPrice() : Money
Returns the price of a product, calculated based on base price quantity 1.00.
getPrice(quantity : Quantity) : Money
Returns the price of a product, calculated based on the passed order quantity.
getPriceBookPrice(priceBookID : String) : Money
Returns the active price of the product in the specified price book for quantity 1.00.
getPriceBookPrice(priceBookID : String, quantity : Quantity) : Money
Returns the active price of the product in the specified price book for the specified quantity.
getPriceBookPriceInfo(priceBookID : String) : ProductPriceInfo
This method acts similarly to getPriceBookPrice(String) but returns a ProductPriceInfo object wrapping the actual price with additional information.
getPriceBookPriceInfo(priceBookID : String, quantity : Quantity) : ProductPriceInfo
This method acts similarly to getPriceBookPrice(String, Quantity) but returns a ProductPriceInfo object wrapping the actual price with additional information.
getPriceInfo() : ProductPriceInfo
Returns the price info of a product, calculated based on base price quantity 1.00.
getPriceInfo(quantity : Quantity) : ProductPriceInfo
Returns the price info of a product, calculated based on the passed order quantity.
getPriceInfos() : Collection
Returns all the price infos of a product that could have been the basis of the storefront price, calculated based on base price quantity 1.00.
getPricePercentage(basePrice : Money, comparePrice : Money) : Number
Calculates and returns the percentage off amount of the passed comparePrice to the passed basePrice.
getPriceTable() : ProductPriceTable
Returns the product price table object.
isPriceRange() : boolean
Returns true if this product is a master product (or product set) and the collection of online variants (or set products respectively) contains products of different prices.

Warning: If the product represented by this model is a master product with numerous variants, this method can be very expensive and should be avoided.

isPriceRange(priceBookID : String) : boolean
Returns true if this product is a master product (or product set) and the collection of online variants (or set products respectively) contains products of different prices in the specified price book.
Methods inherited from class Object
Method Detail
getBasePriceQuantity
getBasePriceQuantity() : Quantity
Returns the quantity for which the base price is defined. This is typically 1.0.
Returns:
the quantity for which the base price is defined.

getMaxPrice
getMaxPrice() : Money
Calculates and returns the maximum price-book price of all variants (for master products) or set-products (for product sets) for base quantity 1.00. This value can be used to display a range of prices in storefront. If the product represented by this model is not a master product or product set, then this method behaves the same as getPrice(). Only online products are considered. If the "orderable products only" search preference is enabled for the current site, then only orderable products are considered. For master products, only variants with all variation attributes configured are considered.

Warning: If the product represented by this model is a master product with numerous variants, this method can be very expensive and should be avoided.

Returns:
Maximum price of all online variants or set-products.

getMaxPriceBookPrice
getMaxPriceBookPrice(priceBookID : String) : Money
Calculates and returns the maximum price in a given price book of all variants (for master products) or set-products (for product sets) for base quantity 1.00. This value can be used to display a range of prices in storefront. This method follows the same rules as getPriceBookPrice(String) in determining the price book price for each variant or set-product. If the product represented by this model is not a master product or product set, then this method behaves the same as getPriceBookPrice(String).
Parameters:
priceBookID - ID of price book the price is requested for, must not be null.
Returns:
The maximum price across all subproducts in the specified price book.

getMinPrice
getMinPrice() : Money
Calculates and returns the minimum price-book price of all variants (for master products) or set-products (for product sets) for base quantity 1.00. This value can be used to display a range of prices in storefront. If the product represented by this model is not a master product or product set, then this method behaves the same as getPrice(). Only online products are considered. If the "orderable products only" search preference is enabled for the current site, then only orderable products are considered. For master products, only variants with all variation attributes configured are considered.

Warning: If the product represented by this model is a master product with numerous variants, this method can be very expensive and should be avoided.

Returns:
Minimum price of all online variants or set-products.

getMinPriceBookPrice
getMinPriceBookPrice(priceBookID : String) : Money
Calculates and returns the minimum price in a given price book of all variants (for master products) or set-products (for product sets) for base quantity 1.00. This value can be used to display a range of prices in storefront. This method follows the same rules as getPriceBookPrice(String) in determining the price book price for each variant or set-product. If the product represented by this model is not a master product or product set, then this method behaves the same as getPriceBookPrice(String).
Parameters:
priceBookID - ID of price book the price is requested for, must not be null.
Returns:
The minimum price across all subproducts in the specified price book.

getPrice
getPrice() : Money
Returns the price of a product, calculated based on base price quantity 1.00. The price is returned for the currency of the current session.

The price lookup is based on the configuration of price books. It depends on various settings, such as which price books are active, or explicitly set as applicable in the current session.

If the product represented by this model is an option product, option prices will be added to the price book price if the price model was initialized with an option model.

If no price could be found, MONEY.NOT_AVAILABLE is returned.

Returns:
the product price.

getPrice
getPrice(quantity : Quantity) : Money
Returns the price of a product, calculated based on the passed order quantity. The price is returned for the currency of the current session.

The price lookup is based on the configuration of price books. It depends on various settings, such as which price books are active, or explicitly set as applicable in the current session.

If the product represented by this model is an option product, option prices will be added to the price book price if the price model was initialized with an option model.

If no price could be found, MONEY.NOT_AVAILABLE is returned.

Parameters:
quantity - Quantity price is requested for
Returns:
the product price.

getPriceBookPrice
getPriceBookPrice(priceBookID : String) : Money
Returns the active price of the product in the specified price book for quantity 1.00.

If the product represented by this model is an option product, option prices will be added to the price book price if the price model was initialized with an option model.

Money.NOT_AVAILABLE will be returned in any of the following cases:

  • priceBookID is null or does not identify a valid price book.
  • The price book has no price for the product.
  • None of the prices for the product in the price book is currently active.
  • The currently active price entry is a percentage.
Parameters:
priceBookID - ID of price book the price is requested for.
Returns:
the price of the product in the specified price book.

getPriceBookPrice
getPriceBookPrice(priceBookID : String, quantity : Quantity) : Money
Returns the active price of the product in the specified price book for the specified quantity.

If the product represented by this model is an option product, option prices will be added to the price book price if the price model was initialized with an option model.

Money.NOT_AVAILABLE will be returned in any of the following cases:

  • priceBookID is null or does not identify a valid price book.
  • quantity is null.
  • The price book has no price for the product.
  • None of the prices for the product in the price book is currently active.
  • The currently active price entry is a percentage.
Parameters:
priceBookID - ID of price book the price is requested for.
quantity - the specified quantity to find the price for.
Returns:
the price of the product in the specified price book.

getPriceBookPriceInfo
getPriceBookPriceInfo(priceBookID : String) : ProductPriceInfo
This method acts similarly to getPriceBookPrice(String) but returns a ProductPriceInfo object wrapping the actual price with additional information.
Parameters:
priceBookID - ID of price book the price is requested for, must not be null.
Returns:
the product price info, or null if not found.

getPriceBookPriceInfo
getPriceBookPriceInfo(priceBookID : String, quantity : Quantity) : ProductPriceInfo
This method acts similarly to getPriceBookPrice(String, Quantity) but returns a ProductPriceInfo object wrapping the actual price with additional information.
Parameters:
priceBookID - ID of price book the price is requested for, must not be null.
quantity - Quantity price is requested for.
Returns:
the product price info, or null if not found.

getPriceInfo
getPriceInfo() : ProductPriceInfo
Returns the price info of a product, calculated based on base price quantity 1.00. The price is returned for the currency of the current session.

This method is similar to getPrice() but instead of just returning the price value, it returns a ProductPriceInfo which contains additional information such as the PriceBook which defined the price and the percentage discount this price point represents.

If the product represented by this model is an option product, option prices will be added to the price book price if the price model was initialized with an option model.

If no price info could be found, null is returned.

Returns:
the product price info, or null if not found.

getPriceInfo
getPriceInfo(quantity : Quantity) : ProductPriceInfo
Returns the price info of a product, calculated based on the passed order quantity. The price is returned for the currency of the current session.

This method is similar to getPrice(Quantity) but instead of just returning the price value, it returns a ProductPriceInfo which contains additional information such as the PriceBook which defined the price and the percentage discount this price point represents.

If the product represented by this model is an option product, option prices will be added to the price book price if the price model was initialized with an option model.

If no price info could be found, null is returned.

Parameters:
quantity - the quantity to use.
Returns:
the product price info, or null if not found.
See Also:

getPriceInfos
getPriceInfos() : Collection
Returns all the price infos of a product that could have been the basis of the storefront price, calculated based on base price quantity 1.00. This will return an empty list if getPriceInfo() would return null, and if there is only one price info in the collection it will be the same price info as getPriceInfo(). Two or more price infos indicate that there are that many price books that meet the criteria for returning the price shown in the storefront.
Returns:
any product price info that could be responsible for the storefront price, or empty collection if there were no product price infos this price model.
See Also:

getPricePercentage
getPricePercentage(basePrice : Money, comparePrice : Money) : Number
Calculates and returns the percentage off amount of the passed comparePrice to the passed basePrice.
Parameters:
basePrice - The assumed 100% price amount
comparePrice - The price to compare to the basePrice
Returns:
The percentage between comparePrice and basePrice (e.g. 90%).

getPriceTable
getPriceTable() : ProductPriceTable
Returns the product price table object. The price table represents a map between order quantities and prices, and also provides % off information to be shown to storefront customers. The price is returned for the currency of the current session.

Usually, the product price table is printed on product detail pages in the storefront.

If the product represented by this model is an option product, option prices will be added to the price book price if the price model was initialized with an option model.

All other methods of this class are based on the information in the product price table.

Returns:
the Product price table.

isPriceRange
isPriceRange() : boolean
Returns true if this product is a master product (or product set) and the collection of online variants (or set products respectively) contains products of different prices.

Warning: If the product represented by this model is a master product with numerous variants, this method can be very expensive and should be avoided.

Returns:
True if this product has a range of prices, false otherwise.

isPriceRange
isPriceRange(priceBookID : String) : boolean
Returns true if this product is a master product (or product set) and the collection of online variants (or set products respectively) contains products of different prices in the specified price book.
Parameters:
priceBookID - The ID of the price book.
Returns:
True if this product has a range of prices, false otherwise.