Learning by Examples: SAP Hybris OOTB Extensions and what is inside. Part 1.


Out-of-the-box SAP Commerce hybris extensions are great examples of how to customize the platform delivered directly from SAP. They can be used as a reference of implementation and, with some exceptions, can be considered as a vendor-recommended best-practice way.  The extensions come in source code form, with comments and documentation. It is a good starting point in finding a solution: the way SAP recommends in their packaged extensions is likely better than anything else, because you never know what side effects you may face if you go with the experimental solution. After all, why to reinvent the wheel? Of course, there are exceptions: not everything is perfect. However, it is important to understand the exceptions too. Learning by examples and design by examples have a lot in common. You can use this approach to upskill junior developers and perfect your own expertise. For me personally, there is no other way to learn solution architecture other than studying the experience of others. While I was examining the extensions, I was taking notes. These notes were put as a basis for the series of articles with this heading. I split the notes in bunches and will publish them as separate blog posts, one per bunch. Later, I’m going to combine the blog posts together and create an index to ease the navigation. The extensions are in the alphabetical order, because their purpose is not very important for the exercise, and grouping them in topics won’t help a lot. I am focusing on what patterns were used in the code rather than how business logic is implemented across the extensions. There are 505 extensions in hybris 6.7, about 15000 java classes and 7000 xmls. Of course, it is a huge work to inspect all extensions and categorize the underlying logic in them. A journey of a thousand miles begins with a single step. So let’s start!

AcceleratorCMS

The acceleratorcms extension provides a number of WCMS components that are designed to be used with your generated storefronts. Inspecting the code of this extension, you will learn
  • How to define custom attribute handlers (CMSUiExperienceRestriction.description)
  • How to define restriction evaluators (CMSUiExperienceRestriction)
  • How to customize a Cache Subsystem:
    • How to define custom cache key providers (there are four defined)
    • How to customize a CMS cache service
  • How to define new preview context information loader strategy. It is used by Context Loader which is used by CMS Site Filter for the storefront.
  • How to define a renderer service: used to get data for the facade layer
  • How to define a deep cloning configuration for a new component and define non-clonable components (such as NavigationComponent)
  • How to define a new cache region (see …cache-spring.xml). It is used to cache the components here. Disabled by default.
  • How to define a backoffice editor area configuration
  • How to define JSP Tags handlers (CMS*Tag.java)
  • How to use Mockito and JUnit + annotations UnitTest

AcceleratorFacades

A facade is an abstraction layer that provides a simplified interface to the underlying implementation, AcceleratorServices.
  • How to define deal with responsive image formats; using media code for setting up the dimensions of the images for each format
  • How to extend the Checkout Flow (facade)
  • How to define attribute convertors
  • How to define model populators. Populators are used to populate or convert the data models objects  into data transfer objects (DTO).
  • How to define page and content convertors
  • How to define content validators. Defines the validation rules for a type. Uses Spring Validation Framework.
  • How to define content predicates. Predicates are used to identify if an attribute type is of a given type or a parameterized type containing the given type. Uses Java Function.
  • How to define reverse populators. They are used to populate attributes from data/dto to models.
  • How to define synchronization visitors (see Visitor pattern). It is used to to collect the items related to an item of which we want to get the synchronization status. It is required for Synchronization Service.
  • Load custom bean definition XMLs for testing purposes (Product Carosel Integration Test)
  • How to use Mockito and JUnit + annotations UnitTest

AcceleratorServices

  • How to define custom ant macros, build callbacks, ant target (syncaddons)
  • How to localize ImpEx files using build time generation, see ImpEx Localization
  • How to use Spring Integration for exporting data and uploading it to external service, for Google Local Shopping Export, see Generating Export Data
  • How to use Spring Integration for Importing data (“HotFolder”)
  • How to define business processes, namely
    • How to create asynchronous processes using business processes and events – see Saved Cart From Upload File process.
  • How to configure backoffice list view, editor area, advanced search widgets for different types (*-backoffice-config.xml)
  • How to create cronjobs (CartRemovalJob, SiteMapMediaJob,..)
  • How to use Java AOP Aspect in hybris
    • For example, for measuring execution time
  • How to use Document Generation Service, namely
    • How to use Renderer Service  with Velocity Template Renderer.
    • How to use it for Emails
  • How to use fraud symptoms (black lists / white lists)
  • How to define an order splitting strategy
  • How to define Search Comparators (for sorting). They are used in Sort Providers.
  • How to define a SiteMap generator for different page types. The list of such generators are used in siteMapMediaJob which creates sitemap.xml. The sitemaps are linked to CMSSite, and combined together by SiteMapController (/sitemap.xml)
  • How to define a custom URL Encoder / URL Decoder / URL Resolver
  • How to use Mockito and JUnit + annotations UnitTest

AcceleratorStorefrontCommons

The acceleratorstorefrontcommons AddOn is a special type of AddOn that encapsulates the common web resources for a storefront. This allows you, for example, to re-use web code that is common to the different Accelerators, such as B2B and Telco.
  • How to use commonweb folder. This folder is processed at the build time. The folder It contains an src folder, which contains defined common Web resources, such as abstract controllers, form data objects, or validators.
  • How to define annotations + AOP Aspects for them.
  • How to define a custom breadcrumbs builder.
  • How to create validators for the forms
  • How to define function classes to use with JSP (such as sanitizeHTML)
  • How to use Mockito and JUnit + annotations UnitTest

AcceleratorWebServicesAddon

The acceleratorwebservicesaddon is the AddOn that extends the Omni Commerce Connect (OCC) API. Its function is to provide resources which depend on the SAP Hybris Commerce Accelerator.
  • How to implement an addon
  • How to extend OCC API
    • How to define a custom serialization (type alias and field set level mappings) for API. See Customizing Commmerce Services.
  • How to use the beforeEach code in IMPEX
    • How to replace a default row resolver in IMPEX (projectdata-acceleratorwebservicesaddon.impex)
  • How to define a custom place order method hook

AccountSummaryAddon

The Account Summary AddOn for the B2B Commerce Accelerator allows users to view their company’s financial history through the B2B site.
  • How to implement an addon
  • How to define a custom breadcrumbs builder.
  • How to implement a page controller
  • How to define a JSP template for a controller
  • How to define JSP tags to use with JSP template
  • How to code styles in LESS format
  • How to define user rights in IMPEX
  • How to upload binary files (images) as a Media via IMPEX
  • How to define a backoffice editor area configuration
  • How to use Mockito and JUnit + annotations UnitTest

AdaptiveSearch

  • How to use FlexibleSearch in the IMPEX export script (impex.exportItemsFlexibleSearch)
  • How to use external CSVs in IMPEXes (impex.includeExternalDataMedia)
  • How to add/modify columns dynamically in IMPEX using beforeEach
    • Using the code/custom functions defined in impex (see commercesearch_import.impex)
  • How to define type interceptors
  • How to define user rights in IMPEX
  • How to use Mockito and JUnit (see Testing Capabilities)
    • + annotations UnitTest
    • + annotations IntegrationTest
 

4 Responses

  1. yexperts

    yexperts

    Reply

    12 May 2018 at 12:10

    Hi Rauf, great idea to write about these extensions! I always said that the best source of documentation in Hybris is the code. Looking forward to the next post in the series.

    It would also be great to tell what not to use as best practice from the OOTB extensions, because there are examples of things done as they should not be (to name just a few – controllers going directly to model and services instead of facades, facades doing direct object creation instead of using converters + populators).

    All the best,
    Cristi C.

  2. Hector

    Hector

    Reply

    23 May 2018 at 12:59

    HI Rauf, is there any examples on how to define a SiteMap Generator ?

Leave a Reply