You are on page 1of 7

6/3/2013

hybris Developer Training Part II Commerce

Commerceservices and
Commercefacades

6/3/2013

commerceservices

Commerceservices & facades

commerceservices extension

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(...){...}

Data model: Product

Commerceservices & facades

Data 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

6/3/2013

commercefacades extension

Commerceservices & facades

commercefacades 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

Data Objects

Commerceservices & facades

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
commercefacadesbeans.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>

6/3/2013

Converters and Populators

Commerceservices & facades

Converters and Populators

Converter

Interface for a converter that transforms an object of type A


into an object of type B

Populator
Interface 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 Populators
Interface for a Populator that uses a collection of options to
control what data is populated

Conceptual Interaction Diagram

Commerceservices & facades

Conceptual Interaction Diagram


storefront

facades

some Service

some

some

Storefront

facade

Controller
user

15. view

services
3. invoke
business service

2. invoke
business action

1. request

6. model(s)
5. model(s)

4. find
model(s)

14. data object(s)

some Data
Access Object

{model to
convert to
data object}
13. data
object

7.
convert
model

some Converter

9. invoke
business service

another Service
{more populators}
8. populate
data object

11.
model(s)

10. find
model(s)

some Populator
12. model(s)

another Data
Access Object

6/3/2013

Implementing classes

Commerceservices & facades

i
Converter

AbstractConverter

AbstractPopulatingConverter

0..*

populators

1..*

populators

Populator

i
ConfigurablePopulator

DefaultConfigurablePopulator

Converters

AbstractConverter:
Base implementation which can be used as a converter and a populator
Recommended to use Spring lookup-method for createTarget

Use case 1: Add a new Converter

Commerceservices & facades

10

Extend commercefacades with custom converters.

yacceleratorfacadesspring.xml
<alias name="defaultDeliveryModeConverter"

alias="deliveryModeConverter"/>
id="defaultDeliveryModeConverter"
parent="abstractPopulatingConverter">
<lookupmethod name="createTarget" bean="deliveryModeData"/>
<property name="populators">
<list>
<ref bean="deliveryModePopulator"/>
</list>
</property>
</bean>

<bean

6/3/2013

Use case 2: Hook into existing types

Commerceservices & facades

11

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 commerceservicesspring.xml
Processed by BeanPostProcessor

foofacadesspring.xml
<bean parent="modifyPopulatorList">
<property name="list" ref="productConverter"/>
<property name="add" ref="fooProductPopulator"/>
</bean>

Use case 3: Extended types and converters

Commerceservices & facades

12

How to hook properly into the type conversion with extended types?
<itemtype code=FooProductextends=Product...
<attribute qualifier=bartype=java.lang.String...

Solution 1
Write custom converter by extending the base type converter
Decide at call level (Controller) which converter should be used

Solution 2
Merge new attributes in ProductData (base type DTO)
Add additional populator to modifyPopulatorList
Populator must do an instance check on source type

6/3/2013

13

You might also like