hybris developer training part ii - commerce - module 05 - commerceservices and commercefacades
DESCRIPTION
.......TRANSCRIPT
6/3/2013
1
1
2
hybris Developer Training Part II – Commerce
Commerceservices andCommercefacades
6/3/2013
2
3commerceservices
Orchestrates platform services to provide complete B2C use cases
Extends more generic functionality from certain hybris extensions to add more B2C features
CommerceCartService (commerceservices)
public ... addToCart(...)
{
cartService.addToCart(...);
promotionsService.updatePromotions(...);
...
}
CartService (platformservices)
public ... addToCart(...){ ... }
commerceservices extension
Commerceservices & facades
4Data model: Product
summary
more concise product description (e.g. in search)
galleryImages
storing multiple images each resized to a number of standard formats expected by the storefront
Data model: Product
Commerceservices & facades
6/3/2013
3
5commercefacades extension
Typical suite of storefront actions that make up a unified multichannel storefront API
Viewing product details
Adding a product to a cart
Adding a delivery address during checkout
Posting a review
Searching for products with a free text search
commercefacades extension
Commerceservices & facades
6Data Objects
Facades return Data Objects to the Caller (Spring MVC Controller)
Typically populated using a subset of data from the hybris ServiceLayer models
Declared within beans.xml
commercefacades‐beans.xml
<bean class="de.hybris.platform.commercefacades.order.data.DeliveryModeData"><property name="code" type="String"/><property name="name" type="String"/><property name="description" type="String"/><property name="deliveryCost"
type="de.hybris.platform.commercefacades.product.data.PriceData"/></bean>
Commerceservices & facades
6/3/2013
4
7Converters and Populators
ConverterInterface for a converter that transforms an object of type A into an object of type B
PopulatorInterface for a populator that sets values in a target instance based on values in the source instance
Type conversion is typically broken down into a pipeline of Population steps
Configurable PopulatorsInterface for a Populator that uses a collection of options to control what data is populated
Converters and Populators
Commerceservices & facades
8Conceptual Interaction Diagram
Conceptual Interaction Diagramstorefront facades services
1. request
some
Storefront
Controller
some
facade
some Converter
some Populator
some Service
some Data Access Object
another Service
another Data Access Object
user 14. data object(s)
2. invoke business action
3. invoke business service
15. view
6. model(s)
12. model(s)
9. invoke business service
5. model(s)4. find
model(s)
11. model(s)
10. findmodel(s)
13. data object
7. convert model
{model to convert to
data object}
{more populators}
8. populate data object
Commerceservices & facades
6/3/2013
5
9Implementing classes
AbstractConverter:
Base implementation which can be used as a converter and a populator
Recommended to use Spring lookup-method for createTarget
Converteri
Populatori
ConfigurablePopulatori
AbstractPopulatingConverterAbstractConverter
ConvertersDefaultConfigurablePopulator
populators
populators
0..*
1..*
Commerceservices & facades
10Use case 1: Add a new Converter
Extend commercefacades with custom converters.
<alias name="defaultDeliveryModeConverter" alias="deliveryModeConverter"/>
<bean id ="defaultDeliveryModeConverter"parent="abstractPopulatingConverter">
<lookup‐method name="createTarget" bean="deliveryModeData"/><property name="populators">
<list><ref bean="deliveryModePopulator"/>
</list></property>
</bean>
yacceleratorfacades‐spring.xml
Commerceservices & facades
6/3/2013
6
11Use case 2: Hook into existing types
<bean parent="modifyPopulatorList"><property name="list" ref="productConverter"/><property name="add" ref="fooProductPopulator"/>
</bean>
foofacades‐spring.xml
How to hook properly into the type conversion to not rewrite the basic code or overwrite existing converters?
modifyPopulatorList to modify existing populator lists
defined in commerceservices‐spring.xml
Processed by BeanPostProcessor
Commerceservices & facades
12Use case 3: Extended types and converters
How to hook properly into the type conversion with extended types?
<itemtype code=“FooProduct” extends=“Product” ...
<attribute qualifier=“bar” type=“java.lang.String” ...
Solution 1Write custom converter by extending the base type converter
Decide at call level (Controller) which converter should be used
Solution 2Merge new attributes in ProductData (base type DTO)
Add additional populator to modifyPopulatorList
Populator must do an instance check on source type
Commerceservices & facades
6/3/2013
7
13