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.