This content has been marked as final. Show 14 replies
PricingModelHolder is used as session scoped component /atg/commerce/pricing/UserPricingModels. You can find following dependency declared to PricingModelHolder in the ProfileFormHandler (class: CommerceProfileFormHandler) through DCS config layer:
Its initialization is done through postLoginUser() so when customer logs in, UserPricingModels component is initialized by querying each pricing engine (item, order, tax and shipping) to load the promotions that the user should have. If during the life cycle of the session, any new promotion gets applied to the user the initialization method can be called again to have updated session cache of promotions.
Actually UserPricingModels component is created and started whenever the user session starts. It can provide you a merged list of global and active promotions for the each pricing engine for transient and persistent user. There is a initializePricingModels() method in PricingModelHolder which is called when the UserPricingModels starts. When I said - initialization done through postLoginUser(), I actually mean to say invocation of this initializePricingModels() method. Internally this initializePricingModels() does nothing but querying each pricing engine - item, order, tax and shipping to load the promotions. After user logs in, PricingModelHolder is re-initialized by invocation of initializePricingModels() through postLoginUser() so that all the promotions that the user might have accumulated during previous sessions can also be cached.
These are just type of discount calculators to be used for standard pricing, bulk pricing, tiered pricing
If you are using standard pricing with items, all your OOTB promotions use Item/Order/ShippingDiscountCalculator.
All global promotions are retrieved from the database and loaded during server startup. This collection of global promotions is periodically refreshed also so that any new global promotions can be loaded as well. GlobalPromotionsDate component is used for the purpose of refreshing global promotions and it uses a scheduler for this purpose. GlobalPromotionsDate component actually resets the time through scheduler which is used in the query to find available global promotions.
difference between the below methods :
public abstract ItemPriceInfo priceItem(CommerceItem commerceitem, Collection collection, Locale locale, RepositoryItem repositoryitem, Map map)
public abstract List priceEachItem(List list, Collection collection, Locale locale, RepositoryItem repositoryitem, Map map)
public abstract List priceItems(List list, Collection collection, Locale locale, RepositoryItem repositoryitem, Order order, Map map)
with clear explanation.
If you are showing only static price you can retrieve and display the list/sale price directly from the SKU object whereas these ItemPricingEngine methods used to dynamically price a single CommerceItem or a list of CommerceItems by taking the promotions into account. Let's look at each of these methods in detail.
The method parameters are usually common input for various pricing operations and together they constitute a pricing context. These are:
public abstract ItemPriceInfo priceItem(CommerceItem commerceitem, Collection collection, Locale locale, RepositoryItem repositoryitem, Map map) throws PricingException;
commerceitem - The single CommerceItem which is to price
collection - Collection of RepositoryItems representing PricingModels (promotions)
locale - Locale to use for pricing
repositoryitem - RepositoryItem for the customer's profile
map - Map of extra parameters to be used in the pricing and can be null
The priceItem() method prices a single CommerceItem and returns ItemPriceInfo object for the passed item. It applies any PricingModels (promotions) that are passed via the second parameter if they are qualified. The single item that is passed in is the only one which is used to qualify the requirements of a promotion. In other words, promotions that relate to only one item are applied and not those which are applicable at Order or Shipping level. E.g. if the CommerceItem passed as parameter is for "1 quantity of A" and there is a promotion for "Buy 2 or more of A, get one free" the promotion would not take effect. This method is usually used for displaying item prices when a customer is browsing the catalog.
Here method arguments are:
public abstract List priceEachItem(List list, Collection collection, Locale locale, RepositoryItem repositoryitem, Map map) throws PricingException;
List - The list of commerce items to price (individually)
Rest of the arguments are same as above.
The priceEachItem method batch processes all the input CommerceItems that are passed into it through the list and price them as single item. It returns a List of ItemPriceInfo objects representing the price quotes for each input item.
Method arguments here are:
public abstract List priceItems(List list, Collection collection, Locale locale, RepositoryItem repositoryitem, Order order, Map map) throws PricingException;
List - The list of commerce items to price (together in same pricing context)
Rest of the arguments are same as previous one.
priceItems method prices all input CommerceItems in the same pricing context and returns list of ItemPriceInfo objects representing the price quotes for the input items. Continuing with the same example, the customer now adds 2 quantity more of item A in the shopping cart so cart now has "3 quantity of A". While the customer is just browsing the catalog, the "Buy 2 or more of A, get one free" promotion is not factored in when displaying prices. And therefore when the customer adds item "A" to the shopping cart, the price shown will still be full price for all the items. However, when the customer subsequently goes on to display the contents of cart, the promotion takes effect and shows that one "A" is free.
Calculators extending this abstract class will have these methods implemented. They are meant to facilitate while pricing based on the context. If multiple items are to be priced, then priceItems will call priceItem iand that internally calls priceEachItem. If only single item is to be calculated, priceItem can be called.