Why Hybris deprecated Jalo layer?

Or Explain difference between Jalo layer and Service layer?

Hybris 4.3.0, deprecated the Jalo layer for item types. This means, that hybris discouraged the usage of Jalo classes to serve as utility methods for performing business logics.

Prior to service layer, Jalo classes used to have both data model logics, methods and also business logic methods.

<itemtype code=”PickingCenter”
autocreate=”true” generate=”true”>
<deployment table=”PICKING_CENTER” typecode=”22113″/>
<attributes>
           <attribute qualifier=”warehouseForFresh” type=”Warehouse”>
           <persistence type=”property” />
           <modifiers read=”true” write=”true” optional=”true” />
           <description>Warehouse for fresh items</description>
</attribute>
</attributes>
</itemtype>

A sample item type in items.xml

The build framework will generate below classed for this item type:

1) An abstract class : GeneratedPickingCenter –  This class is basically a data model class, which has getter/setter for accessing data model, like attributes of data model. 

3

 

2) PickingCenter.java

Non Abstract class : This class extends the Generated class, and can have other methods for accommodating business logic.

So what is the big deal?

1) Service layer comes with the idea of segregating business logic from data model. Service layer sits inside other extensions (not necessarily) and access data layer via DAOs.  This layer is much more flexible and loosely coupled with database.

2) Think of a scenario, where you are using a legacy code, you don’t have access to source code. Had it been all Jalo, How would you override a business logic? In service layer it is easy to override, since ever service is configured as a bean, which is more adaptable to spring MVC design pattern.

3) If there is a change in database design, you need not to change your service layer necessarily. This flexibility is not available in Jalo layers.

4) In Jalo, we use like below:                                                                                                VoucheManager vm = VoucherManager().getInstance();

In Service layer,                                                                                                          private VoucherService voucherService;

So we can inject any implementation of VoucherService in our custom code, but how do we do so in Jalo. We need to break into Jalo layers.

Source : Hybris Wiki

Flexiblesearch error : could not translate value expression ‘session.catalogversion’

This error comes, when we try to access, products, cart etc from outside the context of our web application, like from custom cockpits, third party web services, or a web application within hybris container, but different web application context.

Background

As the error suggests, it could not find the catalog basically, in the session. Since the session associated, with web application is different in our use case, it could not find the catalogs, which are generally attached to base store. A custom web application is not associated with any base store, so it has no catalog attached to it.

Solution

The cockpits developer would have faced the same issue, while developing it, and they were kind enough to give us a solution to this. They called it Impersonation.

The literal meaning of impersonation is, to act on behalf of someone else.

We need to wrap the calling code in a impersonated context. This context could be supplied with, base store, cms sites, user, order and even a catalog. Remember selecting a customer or order in cockpit. Once selected, that user/order is supplied to a impersonated session context, and available to wrapped code to process.

The cmsSite and catalogVersion can be get by service layer convenient methods at disposal.

Once we call our business logic inside execute method, it has catalog version in session.

 

 

 

Set up a MVC application in hybris

Background

There are times, when OOB cockpits, applications are not sufficient for client requirements.  Customizing cockpit is often a tedious task as it involves struggle with adamant ZK framework.

Alternative

Hybris never discouraged us to create more flexible MVC applications and still use the powerful platform features. This acts just like other full fledged application and run inside same hybris server.
1. Create a new extension. Let’s call it Backoffice.
1