Service Layer API
The extensible cart calculation is flexible and customizable thanks to its modular architecture. As opposed to the default implementation of PriceFactory (Europe1PriceFactory), it implements the price, discount, and tax resolving strategies as separate strategies.
DefaultCalculationService (the default Platform implementation for CalculationService) resolves the information required for cart calculation (prices, taxes, discounts, payment and delivery costs) through respective Find[Price,Discount,Tax,Delivery,Payment]..Strategies.
The diagram shows the jalo and the service layer strategies. Here is how they differ:
Jalo
In the jalo find strategies, Platform provides a default implementation of the price, discount, and tax strategies in the single FindPricingWithCurrentPriceFactoryStrategy class. This class implements the FindPriceStrategy, FindDiscountValuesStrategy, FindTaxValuesStrategy resolver strategy interfaces, and uses a configured PriceFactory implementation.
The default implementations for FindDeliveryCostStrategy(DefaultFindDeliveryCostStrategy) and FindPaymentCostStrategy(DefaultFindPaymentCostStrategy) use jalo items to retrieve delivery and payment cost information.
Service layer
In the service layer solution, the implementations of all the strategies used by DefaultCalculationService use only the service layer logic and service layer models. Those strategies have the DefaultSL prefix in the names of the classes.
The service layer approach provides the same logic as the default implementations of the methods from the PriceFactory interface (Europe1PriceFactory).
The diagram shows the interfaces/classes and the interdependencies for both approaches:
As opposed to the jalo approach, the service layer solution provides implementations for the interfaces separately:
|
Interface |
Service layer implementation |
|---|---|
|
FindPriceStrategy |
DefaultSLFindPriceStrategy |
|
FindTaxValuesStrategy |
DefaultSLFindTaxValuesStrategy |
|
FindDiscountValuesStrategy |
DefaultSLFindDiscountValuesStrategy |
|
FindDeliveryCostStrategy |
DefaultSLFindDeliveryCostStrategy |
|
FindPaymentCostStrategy |
DefaultSLFindPaymentCostStrategy |
Those strategies are located in the de.hybris.platform.order.strategies.calculation.impl.servicelayer package.
DefaultCalculationService has a configured switcher that allows you to still use the jalo approach. This switcher decides whether to use either jalo strategies or service layer strategies based on the pdt.calculation.mode property. For more information, see Operation Modes.
Extending DefaultSLFindPriceStrategy through the FindPriceHook Interface
You can extend DefaultSLFindPriceStrategy through an implementation of the FindPriceHook interface. It allows you to modify the default price based on the default price value and its entry. You can use these modifications only when the isApplicable method returns true. Any customs implementations of the FindPriceHook interface need to be defined as Spring beans and registered to the findPriceHooks list.
As only the first implementation of an applicable registered price hook is evaluated at run time, it is impossible to implement chains of multiple modifications. As a consequence, price hook implementations can't overlap with regards to their domain of applicability.