meta data for this page
Commerce Facades - Key Concepts and Features
The commercefacades extension exposes a group of facades which simplify the communication between the store frontend and the service layer. This is a summary which I wrote while studying for the certification. The Hybris Documentation about commercefacades has one page and it is worth reading.
Key Concepts
- The facades return data objects which are completely separated from the models. They can be extend using the file *-beans.xml.
- Each method fulfills a business action.
- The conversion between models and data objects is done by the converters and populators.
- A converter may create the target object and contains a list of populators.
- A populator fills in some fields (or calculates using services) of the data object to be used in the front-end.
- Populators must be independent and must have a clear goal, so they can be easily reused.
- Both are injected using Spring. The new constructor must be avoid.
- Data objects are instanced using a Spring bean with the prototype scope which is defined in beans.xml.
- All the converters are an instance of AbstractConverter or AbstractPopulatingConverter
- ConfigurablePopulators may implement different conversion rules based on a set of enums.
- First the converter creates a data object using all the populators which fill the mandatory fields.
- Then a configurable populator fills the fields which are only required by some components/pages of the front-end. It has a Map<Enum option, populator>.
Key Features
- There are facades for:
- Cart
- Order
- Checkout
- Product (including reviews)
- Search
- StoreSession (languages and currencies)
- User
- StoreLocator
- The extension can be easily extended.
- Adding facades
- New implementation of a facade interface (replacing or adding methods)
- New converters or populators
- Adding or replacing populators
- Extending or new data objects
- yacceleratorfacades is an example of an extension which extends the facades.
- Out-of-the-box converters and populators: commercefacades Extension - Technical Guide
- The URLResolver must be implemented to provide relative URLs for the business objects. Hybris comes with URL resolvers for products, categories and search using facets.
Workflow
The interaction of the controllers, facades, services, DAOs, models and data objects is explained in the this diagram: Simple Request Interaction Diagram.jpg
In the B2C Accelerator the converters and the populators are never used to convert from a DTO to a model. But they could be used.
–Based on Hybris 6.3
Discussion