Extensions

Hybris is collection of several extensions. Extension is address to specific functionality. An extension is unit of functionality in hybris. It is an encapsulated piece of the hybris Commerce Suite that can contain business logic, type definitions, configuration etc. Extensions are independent of one another by default.

Structure of an Extension

A basic extension contains the following directories and files:

you can write a custom extension as per your requirement that use or override existing extensions functionalities. You can create your own extension So every extension in hybris contains

  • Bussiness logic

  • type defintion(items.xml)

  • web application

  • hmc configuration

Hybris provides an ant-based extension generator and provide extension templates for specific function. you can choose any one as per your requirement.


Extgen

Ant extgen command can be used to create an extension. This command uses the specified extension template to create the structure of the new extension. We should not modify any of the existing extension in Hybris. We should always create new extension to define the custom logic in Hybris.

Extension generation Command :

ant extgen

Extension Templates

Hybris provide following extension templates

  • yempty : structure for an extension with a core and web module. It is default extensions.

  • ycommercewebservices : for customize web services extension

  • ycockpit : for customize of cockpit functionalities

  • ybackoffice : for customize backoffice functionalities extension

  • yaddon : for customize for Accelerator AddOns

Create new Extension

  • Create a new extension skeleton using ant extgen command

  • Specify the extension template, name of the extension and package name while running this command

  • After execute command with extension template will create the structure of the new extension.

  • we will be added as the name of the extension inside the extensioninfo.xml file. which make reference the new extension in the localextensions.xml file. So that hybris will consider this extension during the build.

  • Build the Hybris package .

Update localextensions.xml

<extensions><path dir="${HYBRIS_BIN_DIR}" depth="4" />

<!-- Add new ext -->

<extension name="myfirstextension" />

</extensions>


After that , you can start write to your business logic in extension.

Step by Step for new custom extension

  • Open cmd

  • Go to {YourPath}/bin/platform and run setantenv.bat for set ant path.

for example: C:\HYBRIS-1808\hybris\bin\platform

  • type ant extgen command. This will ask you for template

Select yempty for the extension template

Enter the name of the extension. for example: myfirstextension

Enter the package prefix . for example: com.test.myfirstextension

  • The Ant script will create a structure of extension.

{YourPath}/bin/custom/myfirstextension

C:\HYBRIS-1808\hybris\bin\custom\myfirstextension

  • Append the new extension to config/localextensions.xml

open C:\HYBRIS-1808\hybris\config\localextensions.xml file and add new extension

<extension name="myfirstextension"/>

  • Run ant all on cmd

C:\HYBRIS-1808\hybris\bin\platform> ant clean all

  • Start the hybris server hybrisserver.bat

C:\HYBRIS-1808\hybris\bin\platform> hybrisserver.bat

  • Open HAC (hybris administration console) https://localhost:9002/hac

Default Login credential

  • user name : admin

  • password : nimda

  • For checking Installed Extensions, Go to platform->Extensions or https://localhost:9002/platform/extensions

search your extension "myfirstextension" and you will get your extension and webroot will be available for myfirstextension

  • if we do not need a web module for this basic extension, we can disable this in

myfirstextension/extensioninfo.xml

Comment <!--<webmodule jspcompile="false" webroot= "/myfirstextension"/> -->

  • Stop server (ctrl+c) and press y Run ant all and start server

  • Go to browser http://localhost:9001/hac and login again and Go to platform- >Extensions and check webroot for myfirstextension. it will be empty

  • Import the generated extension into your Eclipse and start work on new extension.


Dependencies on other extension

If an extension is dependent on other extensions then it should define those dependencies using requires-extenion tag. Every extension has own extensioninfo.xml file in which we need to add requires-extenion.

<requires-extenion name=”secondextension”>

<requires-extenion name=”thirdextension”>

Modulegen

Ant modulegen command can be used to create the module. It creates the set of extensions based on the module template we select. Generally for B2B and B2C module , it creates 7 extensions which are logically related and grouped.

<extension name='mycommercecore' />

<extension name='mycommercefacades' />

<extension name='mycommercestorefront' />

<extension name='mycommercecockpits' />

<extension name='mycommerceinitialdata' />

<extension name='mycommercefulfilmentprocess' />

<extension name='mycommercetest' />