Monday 24 December 2018

Change site URLs in Hybris


* We can change the site URLs in Hybris with below properties

* Add the below properties to local.properties or project.properties

website.electronics.http=http://electronics.local:9001
website.electronics.https=https://electronics.local:9002
hybrisinstructivestorefront.webroot=
storefrontContextRoot=
hac.webroot=/hac

* Do ant all
* start server

* Access the site.

Thursday 6 December 2018

Modulegen in hybris

*  ant modulegen command used to generate sets of dependent extensions to quickly start new projects or create new applications.
 *  The modulegen tool replaces the schema, package name, extension class prefixes, and some other properties across a set of extensions
 * 7 extensions generate for b2c & b2b accelerator.


Follow the below steps to generate a set of extensions,

Step 1:- Go to platform directory and run ‘ant modulegen’ command.

ant modulegen -Dinput.module=accelerator -Dinput.name=training -Dinput.package=de.hybris.training -Dinput.template=develop
· input.module parameter: Defines the accelerator module.
· input.name value: Prefix that is added to the new extensions generated by modulegen.
· input.package value: Defines the package prefix.
· input.template parameter: Defines how to use Hybris Commerce 
configuration.

Step 2:- A set of extensions will be generated and place that extensions in localextensions.xml file.




Step 3:- remove any of the following extensions that might appear in your localextensions.xml file
yacceleratorcore
yacceleratorfacades
yacceleratorstorefront
yacceleratorinitialdata
yacceleratortest
yacceleratorcockpits
yacceleratorfulfilmentproces

Step 4:- start the server


Step 5:- initialize the system from HAC.




Step 6:- you must have the following entry in your computer's hosts file:

127.0.0.1   electronics.local 






Step 7:- Access the site with below URl

https://electronics.local:9002/hybrisinstructivestorefront/


EXTGEN in hybris

  
*  SAP Commerce comes with an extension generator system called extgen.
*  You can create new extensions based on extension templates. 
*  To add your own template extension to the selection of extgen templates please add the following line to the extensioninfo.xml of your extension.
<meta key="extgen-template-extension" value="true" />

Follow the steps to create custom backoffice extension.

Step 1:- Go to platform directory and run ant extgen command.



Step 2:- Select the extension template you want to generate.(ybackoffice)





Step 3:- Enter the extension name.



Step 4:- Enter the package name.



Step 5:- Register as a SASS extension? ([true], false)
If you select ‘true’ the generated extension contains Sass registration in the buildcallbacks.xml file.

The variables file myextension-variables.scss is also created in the myextension/backoffice/resources/scss directory


Step 6:- Create a sample widget? ([true], false)

    It will decide if you want a sample widget to be generated. If not, do not forget to manually create a widgets folder in myextension/backoffice/resources directory.

Here, you can add a new directory for each component that you create.



Step 7:- Create sample style sheets? (true, [false])

Decide if you want a sample style sheets to be generated



Step 8:- Add the new extension to your localextensions.xml file (config folder).



Note:- To load all custom extensions automatically into the localextensions.xml file, add the following line, at the beginning of the file.
<path autoload="true" dir="${HYBRIS_BIN_DIR}/custom"/>

Step 9:- Do ant all & start the server.



Wednesday 5 December 2018

Reading properties from local.properties file in Hybris


 *  To get the property from local.properties file and use in class.
*  Here I want to show description when  training.product.description” property is   true in local.properties otherwise I don't want to show  
*  To get the property from local.properties file and use in class.
*  Here I want to show description when  training.product.description” property is true in local.properties otherwise I don't want to show description in the storefront.
*  We can do it in two ways, Check the below example, in the storefront.

*  We can do it in two ways, Check the below example,



TrainingProductDetailsController.java

Method 1:-
Here I am using Config class to get the property. Its looks very short and simple to do it.


import de.hybris.platform.util.Config;

private static final String TRAINING_PRODUCT_DESCRIPTION = "training.product.description";

final String descriptionCheck = Config.getParameter( TRAINING_PRODUCT_DESCRIPTION);

model.addAttribute("descriptionCheck", descriptionCheck);


Method 2:-
Here I am using ConfigurationService. It looks lengthy,
  
           import de.hybris.platform.servicelayer.config.ConfigurationService;
     
          private static final String ORDERPALCED_MESSAGE = "training.product.description";

            final String descriptionCheck= configurationService.getConfiguration().getProperty(ORDERPALCED_MESSAGE);
        model.addAttribute("descriptionCheck", descriptionCheck);



local.properties


training.product.description = true




*  Here I am writing the condition to display description.

JSP:- TrainingProductDetails.jsp


<c:if test="${descriptionCheck eq true }">
<td>${productData.description}</td>
</c:if>



BackOffice

Requirement:-  Create new Tab, attributes ,Tree node in BackOffice.

1. Create trainingbackoffice extension.
2. Create new tab and add attributes to the tab for Customer.
3. Create new Tree node and add to advanced search fields and simple search.


Step 1:-  Create trainingbackoffice extension.

* Goto platform directory and run  ‘ant extgen’.
* Select ‘ybackoffice’ template.
* Give name and package and saas .
* New folder created in custom folder.
* Import to eclipse.

Step 2:-  Create new tab and add attributes to the tab for Customer.

*  Open  /hybrisbackoffice/resources/hybrisbackoffice-backoffice-config.xml
 and add this code


<config xmlns="http://www.hybris.com/cockpit/config"
xmlns:editorArea="http://www.hybris.com/cockpitng/component/editorArea"
xmlns:list-view="http://www.hybris.com/cockpitng/component/listView"
xmlns:advanced-search="http://www.hybris.com/cockpitng/config/advancedsearch"
xmlns:df="http://www.hybris.com/cockpitng/component/dynamicForms"
xmlns:dsb="http://www.hybris.com/cockpitng/config/dashboard"
xmlns:explorer-tree="http://www.hybris.com/cockpitng/config/explorertree"
xmlns:grid-view="http://www.hybris.com/cockpitng/component/gridView"
xmlns:na="http://www.hybris.com/cockpitng/config/notifications"
xmlns:simple-search="http://www.hybris.com/cockpitng/config/simplesearch"
xmlns:wz="http://www.hybris.com/cockpitng/config/wizard-config"
xmlns:y="http://www.hybris.com/cockpit/config/hybris">

<context merge-by="type"  type="Customer" component="editor-area">
<editorArea:editorArea>
<editorArea:tab name="hmc.tab.customer.custom"
position="1">
<editorArea:section name="hmc.section.customer.attributes">
<editorArea:attribute qualifier="dob" />
<editorArea:attribute qualifier="age" />
</editorArea:section>
</editorArea:tab>
 </editorArea:editorArea>
</context>
</config>



=>Open hybrisbackoffice-locales_en.properies file and add this

type.Customer.dob.name=Date Of Birth
type.Customer.age.name=AGE

=>Open labels_en.properties in hybrisbackoffice extension and add this

hmc.tab.customer.custom =CUSTOM

hmc.section.customer.attributes=ATTRIBUTES


=>Do ant build and update system by selecting running system & localization
=>Or go to Backoffice F4 and reset everything






Step 3:- Create new Tree node and add to advanced search fields and simple search.

=>Open /hybrisbackoffice/resources/hybrisbackoffice-backoffice-config.xml file and add this code


<config xmlns="http://www.hybris.com/cockpit/config"
xmlns:editorArea="http://www.hybris.com/cockpitng/component/editorArea"
xmlns:list-view="http://www.hybris.com/cockpitng/component/listView"
xmlns:advanced-search="http://www.hybris.com/cockpitng/config/advancedsearch"
xmlns:df="http://www.hybris.com/cockpitng/component/dynamicForms"
xmlns:dsb="http://www.hybris.com/cockpitng/config/dashboard"
xmlns:explorer-tree="http://www.hybris.com/cockpitng/config/explorertree"
xmlns:grid-view="http://www.hybris.com/cockpitng/component/gridView"
xmlns:na="http://www.hybris.com/cockpitng/config/notifications"
xmlns:simple-search="http://www.hybris.com/cockpitng/config/simplesearch"
xmlns:wz="http://www.hybris.com/cockpitng/config/wizard-config"
xmlns:y="http://www.hybris.com/cockpit/config/hybris">

<context component="explorer-tree" module="hybrisbackoffice" merge-by="module">
<n:explorer-tree xmlns:n="http://www.hybris.com/cockpitng/config/explorertree">
<n:navigation-node id="Training_Product">
<n:type-node code="TrainingProduct" id="TrainingProduct"/>
</n:navigation-node>
</n:explorer-tree>
</context>
<context type="TrainingProduct" component="listview" merge-by="type" parent="GenericItem">
<list-view:list-view>
<list-view:column qualifier="code" />
<list-view:column qualifier="name" />
<list-view:column qualifier="description" />
</list-view:list-view>
</context>
 <context merge-by="type"  type="TrainingProduct" component="editor-area">
<editorArea:editorArea>
<editorArea:tab name="hmc.tab.customer.common" position="1">
<editorArea:section name="hmc.tab.customer.common">
<editorArea:attribute qualifier="code" />
<editorArea:attribute qualifier="name" />
<editorArea:attribute qualifier="description" />
</editorArea:section>
</editorArea:tab>
 </editorArea:editorArea>
</context>
<context type="TrainingProduct" component="advanced-search" merge-by="type" 
parent="GenericItem">
<advanced-search:advanced-search>
<advanced-search:field-list>
<advanced-search:field name="code" operator="equals" selected="true" />
<advanced-search:field name="name" operator="equals" selected="true" />
<advanced-search:field name="description" operator="equals" selected="true"/>
</advanced-search:field-list>
</advanced-search:advanced-search>
</context>
<context type="TrainingProduct" component="simple-search" merge-by="type" parent="GenericItem">
<simple-search:simple-search>
<simple-search:field name="code" />
</simple-search:simple-search>
</context>
</config>

=>Add properties in

hybrisbackoffice-locales_en.properies
 &
/hybrisbackoffice/resources/hybrisbackoffice-backoffice-labels/labels_en.properties

type.TrainingProduct.code.name =CODE
type.TrainingProduct.name.name =NAME
type.TrainingProduct.description.name =DESCRIPTION


hmc.section.TrainingProduct=TRAINING PRODUCT

hmc.tab.customer.common =COMMON

=>Do ant build and update by selecting localized type & running system.