gtag

Hybris - Ordering of one to many relations.

 To order one to many relations in Hybris, Follow the following steps. 


1. add collectiontype="list" and order="true" to the relation type.

    <relation localized="false" code="Product2Topic"> 
       <sourceElement type="Product" cardinality="one" qualifier="product"/> 
       <targetElement type="Topic" cardinality="many"                  
                        qualifier="topic" collectiontype="list" ordered="true"/> 
    </relation>

2. import impex with target elements in a single line with order.

    INSERT_UPDATE Topic; code [unique = true];topic[lang = en];
    ;Technical;"Technical" 
    ;Product;"Product" 
    ;Other;"Other" 

    INSERT_UPDATE Partner; uid[unique = true]; topic(code); 
    ;01; Technical, Product, Other


Bots/Crawlers session management at Tomcat Valves

Tomcat Valves are nothing but filters at the container level.

Conventional servlet filters are at request specific whereas Tomcat Valves will act as filters for the whole container instead of a specific requests.



OOTB Implementation CrawlerSessionManagerValve : 

1. It identifies whether the request comes from Bots/Crawlers or from legitimate users.

2. If the request is from bots :

  • Store the session ID in a Map and use the same session ID for all the requests from the same Bot/Crawler.
  • Key: request.getHost() + request.getContext() + clientIp
  • Value:  Session ID

 3. This way we can reduce the number of sessions created by Bots. Otherwise, a huge number of requests from Bots will create too many session objects which are not desirable. 


Overriding OOTB Tomcat Valves or Create Custom Tomcat Valve :


Please refer to this link: https://stackoverflow.com/questions/6573325/implementing-tomcat-custom-valve




Apache Basic Authentication interfering with Hybris HAC login.

Issue : 

When there is a Apache Basic Authentication is enabled for HAC, It will affect the HAC login form.
That means, If you enter the Apache Basic Authentication credentials then those will be submitted to HAC login form. 


Solution :

This issue occurs because there are two possible configurations for login to HAC
  • <http-basic />
  • Form
Remove <http-basic /> from platform/ext/hac/web/webroot/WEB-INF/config/spring-security-config.xml


This can be done as part of the ant target :  ant customize 

Hybris Server Startup issue


 Hybris Server Startup issue : Detected different Solr server running on the same port for instance

Log:

ERROR [localhost-startStop-1] [HybrisContextFactory] Error initializing global application context!
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultSolrServerService' defined in class path resource [global-solrserver-spring.xml]: Invocation of init method failed; nested exception is de.hybris.platform.solrserver.SolrServerException: Detected different Solr server running on the same port for instance: [name: default, port: 8983]


Explanation:


The solr comes as a standalone server. When we stop hybris server by ctrl+c from the command prompt, the hybris server communicates to the solr server to stop. Sometimes, due to this hard stop, the communication might not be established from the hybris server to the solr server, which in turn results in a a hung state. Now, when we restart the hybris server the (already) started solr server is not able to instantiate/register the (bean) services which are required by the hybris server to communicate with the solr and hence the hybris server does not gets back the signal that the (solr) services have been initialized in the solr context.
You can check in the processlist of the server on the port (default 8983) and you will find the solr server running (in actually a non-responsive mode)
Solution: Please do ant clean all and try again. You would be able to successfully restart the server

Under the following folder directory, you can see the solr.xml. In that you can modify the port number of solr server.

hybris\config\solr\instances\default\solr.xml

<solr>
    <str name="configSetBaseDir">${configSetBaseDir:./configsets}</str>
    <str name="coreRootDirectory">${coreRootDirectory:./cores}</str>

    <solrcloud>
        <str name="host">${host:}</str>
        <int name="hostPort">${jetty.port:8983}</int>
        <str name="hostContext">${hostContext:solr}</str>

        <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>

        <int name="zkClientTimeout">${zkClientTimeout:30000}</int>
        <int name="distribUpdateSoTimeout">${distribUpdateSoTimeout:600000}</int>
        <int name="distribUpdateConnTimeout">${distribUpdateConnTimeout:60000}</int>
    </solrcloud>

    <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
        <int name="socketTimeout">${socketTimeout:600000}</int>
        <int name="connTimeout">${connTimeout:60000}</int>
    </shardHandlerFactory>
</solr>

 

Create Email using business process in hybris

1. Create your own business process model.

<itemtype code="ContactUsProcess" extends="StoreFrontCustomerProcess"
jaloclass="de.hybris.platform.commerceservices.jalo.process.ContactUsProcess"
autocreate="true" generate="true">
<attributes>
<attribute qualifier="information" type="StringCollection">
<persistence type="property" />
</attribute>
<attribute qualifier="industry" type="StringCollection">
<persistence type="property" />
</attribute>
<attribute qualifier="firstName" type="java.lang.String">
<persistence type="property" />
</attribute>
<attribute qualifier="lastName" type="java.lang.String">
<persistence type="property" />
</attribute>
<attribute qualifier="customerEmail" type="java.lang.String">
<persistence type="property" />
</attribute>
<attribute qualifier="phone" type="java.lang.String">
<persistence type="property" />
</attribute>
<attribute qualifier="languageType" type="java.lang.String">
<persistence type="property" />
</attribute>
<attribute qualifier="title" type="java.lang.String">
<persistence type="property" />
</attribute>
<attribute qualifier="companyName" type="java.lang.String">
<persistence type="property" />
</attribute>
<attribute qualifier="line1" type="java.lang.String">
<persistence type="property" />
</attribute>
<attribute qualifier="line2" type="java.lang.String">
<persistence type="property" />
</attribute>
<attribute qualifier="city" type="java.lang.String">
<persistence type="property" />
</attribute>
<attribute qualifier="region" type="java.lang.String">
<persistence type="property" />
</attribute>
<attribute qualifier="postalCode" type="java.lang.String">
<persistence type="property" />
</attribute>
<attribute qualifier="country" type="java.lang.String">
<persistence type="property" />
</attribute>
<attribute qualifier="comment" type="java.lang.String">
<persistence type="property" />
</attribute>
</attributes>
</itemtype>
2.  Create Event Class. refer ContactUsEvent.java in zip file. (* don't forget to create bean in *spring.xml)
3.  Create Event Lister class. refer ContactUsEventListener.java in zip file. (* don't forget to create bean in *spring.xml)
4.  Create Context class. refer ContactUSEmailContext.java in zip file. (* don't forget to create bean in *spring.xml)
5.  Create process xml. refer contactUSProcess.xml in zip file.
6.  Create bean as follows in *core-spring.xml.
    
<bean id="contactUsProcessDefinitionResource"
class="de.hybris.platform.processengine.definition.ProcessDefinitionResource">
<property name="resource"
value="classpath:/canselcore/processes/contactUSProcess.xml" />
</bean>
7. Create bean as follows in *core-spring.xml to use your own email template. (This is used in contactUSProcess.xml)
    
<bean id="generateContactUsEmail" parent="abstractGenerateEmailAction">
<property name="frontendTemplateName" value="ContactUSEmailTemplate" />
</bean>
8. Create Email Template as follows.

  # Email page Template
INSERT_UPDATE EmailPageTemplate;$contentCV[unique=true];uid[unique=true];name;active;frontendTemplateName;subject(code);htmlTemplate(code);restrictedPageTypes(code)
;;ContactUSEmailTemplate;Contact us Email Template;true;contactUSEmail;cansel_Email_contactUS_Subject;cansel_Email_contactUS_Body;EmailPage

# Templates for CMS Cockpit Page Edit
UPDATE EmailPageTemplate;$contentCV[unique=true];uid[unique=true];velocityTemplate[translator=de.hybris.platform.commerceservices.impex.impl.FileLoaderValueTranslator]
;;ContactUSEmailTemplate;$jarResourceCms/structure-view/structure_subscriptionExpiredEmailTemplate.vm
    INSERT_UPDATE ContentSlotForTemplate;$contentCV[unique=true];uid[unique=true];position[unique=true];pageTemplate(uid,$contentCV)[unique=true][default='ContactUSEmailTemplate'];contentSlot(uid,$contentCV)[unique=true];allowOverwrite
;;SiteLogo-ContactUSEmailTemplate;SiteLogo;;SiteLogoSlot;true
;;TopContent-ContactUSEmailTemplate;TopContent;;EmailTopSlot;true
;;BottomContent-ContactUSEmailTemplate;BottomContent;;EmailBottomSlot;true
# Email Pages
INSERT_UPDATE EmailPage;$contentCV[unique=true];uid[unique=true];name;masterTemplate(uid,$contentCV);defaultPage;approvalStatus(code)[default='approved']
;;contactUSEmail;Contact Us Email;ContactUSEmailTemplate;true
# Email velocity templates
INSERT_UPDATE RendererTemplate;code[unique=true];contextClass;rendererType(code)[default='velocity']
;cansel_Email_contactUS_Subject;$emailPackageName.ContactUSEmailContext
;cansel_Email_contactUS_Body;$emailPackageName.ContactUSEmailContext
9. Under email-content_en.impex. update the cansel_Email_contactUS_Subject & cansel_Email_contactUS_Body with appropriate template script.

    # CMS components and Email velocity templates
UPDATE RendererTemplate;code[unique=true];description[lang=$lang];templateScript[lang=$lang,translator=de.hybris.platform.commerceservices.impex.impl.FileLoaderValueTranslator]
;cansel_Email_contactUS_Subject;"Contact Us Subject";$emailResource/email-contactUSEmailSubject.vm
;cansel_Email_contactUS_Body;"Contact Us Body";$emailResource/email-contactUSEmailBody.vm
10. Please refer email-contactUSEmailSubject.vm & email-contactUSEmailBody.vm in zip file.

11. Trigger the event from any service class. For instance, You can refer DefaultContactUsService.java in zip file.
You can dowload the zip file from the following link.

Composite component in hybris

The composite component is nothing but the one to many relations between two components.

For Example: 


Please refer the below item changes for the above composite component

Child component :
<itemtype code="LeaderShipImageComponent" autocreate="true" generate="true" extends="CMSImageComponent">

  <attributes>
    <attribute qualifier="lsname"type="localized:java.lang.String">
      <description>Heading</description>
      <persistence type="property" />
    </attribute>
    <attribute qualifier="lsimage" type="Media">
      <description>Tagline</description>
      <persistence type="property" />
    </attribute>
  </attributes>
</itemtype>
   
Parent component : 
<itemtype code="LeaderShipComponent" autocreate="true" generate="true" extends="CMSImageComponent">
   <attributes>
    <attribute qualifier="heading"type="localized:java.lang.String">
      <description>Heading</description>
      <persistence type="property" />
    </attribute>
   </attributes>
</itemtype>

Relation between parent component and child component :
<relation localized="false" code="LeaderShipToLeaderShipImageRelation">
   <sourceElement qualifier="leaderShipComponent" cardinality="one" type="LeaderShipComponent"></sourceElement>
   <targetElement qualifier="leaderShip" cardinality="many" type="LeaderShipImageComponent"></targetElement>
</relation>


Impex changes:

INSERT_UPDATE LeaderShipComponent;$contentCV[unique=true];uid[unique=true];name;leaderShip(uid,$contentCV);&componentRef
;;SampleLeaderShip1Component;Sample LeaderShip 1 Component;"SampleLeaderShipImageComponent1A,SampleLeaderShipImageComponent1B,SampleLeaderShipImageComponent1C,SampleLeaderShipImageComponent1D";SampleLeaderShip1Component

INSERT_UPDATE LeaderShipImageComponent;$contentCV[unique=true];uid[unique=true];name;lsname;lsrole;
;;SampleLeaderShipImageComponent1A;Sample LeaderShip Image Component 1A;Dr. Arjang Nowtash;President.;
;;SampleLeaderShipImageComponent1B;Sample LeaderShip Image Component 1B;Victor Michaud;Vice President, Ontario, Quebec, and Atlantic Canada;
;;SampleLeaderShipImageComponent1C;Sample LeaderShip Image Component 1C;Gerry Hagglund;Vice President, Manitoba;
;;SampleLeaderShipImageComponent1D;Sample LeaderShip Image Component 1D;Shahab Soltani;Vice President, Alberta;

Patent component JSP (leadershipcomponent.jsp):

<div class="container">
 <div>
   <h4>${component.heading}</h4>
 <c:forEach items="${component.leaderShip}" var="leadership">
   
      <cms:component component="${leadership}" />
 </c:forEach>
 </div>
</div>

Child component JSP (leadershipimagecomponent.jsp):

<div>
   <img alt="officedesign-project-management"                                src="${component.lsimage.url}">
     <h4>${component.lsname}</h4>
</div>


Url encoding in hybris

You can change the order of the url encoding attributes or remove those for cms site. 
You can change it directly in hmc, WCMS ---> cmssite ---> url encoding attributes. Update these attributes in site.impex (preferable) instead of doing in hmc.
Please find the following image for your reference.
 

URL customization in Hybris

  1. Update the local.propetries entries as follows.
    website.sample.http=http://sample.local:9001/store
    website.sample.https=https://sample.local:9002/store
    samplestorefront.webroot=/store
    samplestorefrontContextRoot=/store
  2. Update the following entry in extensioninfo.xml under storefront.
    webmodule jspcompile="false" webroot="/store"
  3. update site url pattern in site.impex as follows.
    (?i)^https?://sample.[^/]+(|/.|\?.)$
  4. Update the urlEncodingAttributes. ex: language, storefront
  5. add following entry in host file.
    127.0.0.1 sample.local 
  6. now access the store with https://sample.local:9002/store/