Extension

SAP Commerce is a modular monolith in which the business logic and functionalities are developed using so-called extensions.

To read more theory about extensions take a look at SAP help. If you need some real-life hints -> scroll down.

  • Extension is a function-specific module ​
  • Used to separate newly developed business logic​
  • Extension can contain business logic, type definitions, a web application and back-office configurations​
  • SAP Commerce provides many OOTB extension templates available (yempty, yvoid, …)​
  • Platform provides ant-based tool (extgen) to generate new extensions based upon existing templates

Addon

  • AddOn is a regular extension!
  • Use it to extend or customize Accelerator with additional front-end components
  • AddOn gives a possibility to extend the Accelerator without touching its core codebase​
  • hybris docs

Features of Addons

Addons are MODULAR

  • Front-end files (CSS, JS, HTML, JSP for custom components) are separated from the rest of front-end files.
  • Addons are self-contained

Addons are REUSABLE

  • ‘Reusable’ means you can use any combination of Addons in your SAP Commerce implementation and you can easily reuse the addon in another project.
  • Addons are an essential step in extending Accelerators and minimizing the effort during the upgrade of platform – your files will not be overridden

Easily (un)pluggable

  • AddOns can be easily removed from the project, without the necessity of refactoring the code of your extensions

Addons FAQ

When shall I create the addon instead of plain extension?

Whenever you want to customize or extend the storefront functionalities/capabilities.

How to generate extension?

Platform provides many extension templates to be used together with ‘ant extgen‘ tool to bootstrap the code. Choose the template consciously – you do not have to use yempty all the time!

Some of the less known templates are:

  • yvoid – a very convenient template with a minimal set of files created (*-spring.xml, project.properties, extensioninfo.xml)​
  • yhacext – use it if you want to extend /hac functionalities​
  • ybackoffice – creates a stub for extending Backoffice capabilities​

When addon files are compiled?​

SAP Commerce build process in case of addons is non-intuitive but essential to understand:​

  • First of all, sources from the addons ({some-feature}addon/acceleratoraddon/*) are being copied to the storefront (classes to {projectX}storefront/web/addonsrc/{some-feature}addon/, jsps to {projectX}storefront/web/webroot/WEB-INF/views/addons/{some-feature}addon/).
  • Then the storefront is being built (storefront classes + newly copied addons classes).​

Do I have to run ant all again?

If you are just changing storefront content like JSP/JS/CSS/images, then you do not have to run build to copy the files from addon to storefront. Simply change the file directly in addon and the AddonFilter will take care of the copy process in the background.​

Will only work if you have enabled AcceleratorAddOnFilter: addonfilter.active=true​

How do I install an addon?

To configure addon for given storefronts you shall use addoninstall tool​

ant addoninstall –Daddonnames="MyNewAddon,SomeAnotherAddon" ​
-DaddonStorefront.<storefrontTemplateName>="StoreFront1,Storefront2"​

Addon + extension convention

First of all, you should create addon per granular business functionality.​

However, if additional services/facades are needed by your addon then put them into dedicated extension – due to specific compile order of addon classes (which are first copied to storefront) it is not easy to reuse addons services/facades in other extensions.​

How does the minimum extension look like?

It turns out that extensioninfo.xml is the only mandatory file for an extension – you can remove other files and SAP Commerce will not object 😉

BTW, since we are talking about file removal…

Cleanup your extension!

Depending on the template you have chosen to generate the extension, you might obtain a lot of boilerplate which should be cleaned up before you push any of your changes.

  • Remove unused JS, CSS files and images
  • Delete redundant i18n files (message/*.properties, localization/*.properties) for languages you do not support
  • Are you not extending the data model? – remove *addon-items.xml​
  • ​Are you not creating custom / extending existing DTO objects? – remove *beans.xml
  • Remove unused Impex template files

Use project.properties template!

Instead of hardcoding your properties in project.properties use project.properties.template. SAP Commerce build process will create the file automatically on the basis of template and will substitute yacceleratorstorefront string by the actual storefront name on which the addon is being installed.​

Do not commit the addons project.properties.

As simple as that. Commit just the template file.​


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *