Sunday 31 March 2019

Dynamic Attribute

The following example shows the configuration of the Dynamic Attribute in the items.xml file:

<itemtype code="Accommodation" autocreate="true" generate="true" jaloclass="de.hybris.platform.test.Accommodation">
<attributes>
                <!-- ... -->
                <attribute type="java.lang.String" qualifier="daysHumanReadable">
                <persistence type="dynamic" attributeHandler="accommodationDays" />
                <modifiers read="true" write="false" />
                </attribute>
                <!-- ... -->
</attributes>
</itemtype>

AccommodationDays.java


public class AccommodationDays implements DynamicAttributeHandler<String, AccommodationModel>
{

 @Override
 public String get(final AccommodationModel model)
 {
                String daysWord;
  final int days = model.getDays();
                if (days == 1)
                {
                       daysWord = "day";
                } 
                else
                {
                       daysWord = "days";
                }
                return days + " " + daysWord;
 }

 @Override
 public void set(final AccommodationModel model, final String value)
 {
  throw new UnsupportedOperationException();
 }

}


It is recommended to implement the above method to throw an exception, because the write modifier of the daysHumanReadable attribute is set to false. Thus there is no setter generated in the AccommodationModel.

we can get the value based on some business logic.

SAP WCMS (Web Content Management System)

Web content management module is used for the management of content across multiple channels. The WCMS Cockpit provides a simple way for cockpit users to manage their website pages. It provides an intuitive, graphical user interface for data presentation and management. The WCMS Cockpit also supports workflow and synchronization tasks.


WCMS Module Extensions
WCMS Cockpit  works on CMSCockpit extension. The WCMS Cockpit, you can manage the pages of a website constructed using the CMS2 extension. You can also use the extended components included in the CMS2Lib extension to manage the website pages
The WCMS Cockpit contains the following areas −
Navigation AreaOn the left hand side, you have the navigation pane, where you can navigate to Shortcuts, Queries, Websites and the History tab
*History Box: Last 20 transactions we can undo.
*Info Box: workflow tasks assigned to you
*Queries: 

Browser Area : In the center, you have the Browser area, which is used to manage web content for all the channels. You can add Top Header, Bottom Header and Footer
Content Editor Area:
On the right hand side, you have the Cockpit area. The following options are available under the Editor area in the Basic Category −
  • Name
  • Page title
  • Page Template
  • Catalog Version
  • Label
  • Homepage, etc

Hybris miscellaneous topics

1) How to add message property with css

JSP:
<formElement:formCheckbox idKey="add-mycompany-checkbox" labelCSS="checkbox-wrapper m-b-1" labelKey="mycompany.select.termsandconditions"  path="termsAndConditions" mandatory="true" />

base.properties
mycompany.select.termsandconditions = <span class="checkbox-text ma-label-font">I confirm that the information I have provided is accurate, and I agree to Mycompany <a class="a-link" target="_blank" href="https://www.mycompany.govt.nz/Pages/terms-and-conditions.aspx"> terms and conditions </a> and <a class="a-link" target="_blank" href="https://www.mycompany.govt.nz/Pages/privacy-policy.aspx"> privacy policy</a>. </span>


2)  How to add Dynamic parameters
jsp:
<spring:theme code="mycompany.property.invalid.attempts.count.max.message" arguments="${jalosession.tenant.config.getParameter('mycompany.max.failed.attempts.count')} ,${jalosession.tenant.config.getParameter('mycompany.max.failed.attempts.hour')}" htmlEscape="false"></spring:theme>

base.properties
mycompany.property.invalid.attempts.count.max.message=<h5 class="ma-h5"> Account locked</h5><p>You have entered the incorrect number and PIN combination {0} times. You will not be able to add another property for {1} hours.</p>


3) How to read property key in jsp

<spring:theme code="mycompany.property.invalid.attempts.count.max.message" arguments="${jalosession.tenant.config.getParameter('mycompany.max.failed.attempts.count')} ,${jalosession.tenant.config.getParameter('mycompany.max.failed.attempts.hour')}" htmlEscape="false"></spring:theme>

mycompany.max.failed.attempts.count key defined in project.properties or base.properties

4) How to check anonymous customer in jsp
jalosession.attributes['user'].anonymousCustomer

5) Delete typecode from deployment table - same typecode for multiple items ( old one removed but still in deployment table)

DELETE FROM <YOUR DB NAME>.ydeployments WHERE Typecode=18001(deployment code);

change the development code what ever you have conflicts in my case its 18001 is the conflicting deployment code.

Friday 15 December 2017

SAP Hybris ServiceLayer Architecture

 Service Layer Architecture

The ServiceLayer can be described as a layer of services on top of the persistence layer. The services themselves can be divided into subcomponents.



Components

Client 

A client in this context is any software component that uses the ServiceLayer, such as:

  1. Page Controllers of an MVC framework
  2. Web Service clients
  3. Scripts
  4. Other services

Services

A service holds the logic to perform business processes and provides this logic through a number of related public methods. These public methods usually are defined in a Java interface. Most often these methods operate on the same kind of model object, for example product, order, and so on.
Services are expected to abstract from the persistence layer, that is, to only contain functional logic and no persistence-related code. That means if you implement a service, make sure to implement it in a way that the underlying implementation is as loosely coupled to the persistence layer as possible.
SAP Hybris Commerce exposes all of its functionality through services. The following kinds of services are available:

  1. Business Services implement business use cases, such as cart handling or back order.
  2. Infrastructure Services provide the underlying technical foundation, such as internationalization, import, export, and so on.
  3. System services provide functionality required by the ServiceLayer, such as model handling and session handling.

The service methods should be as fine-grained as possible to enable reuse.
Extensions must provide their functionality as services. Per extension you may provide as many services as you deem necessary, not just one.
Services may use other services to perform their tasks but should keep their inter dependencies to a minimum to avoid overly tight coupling with other components.
In a project, you may write your own services to either provide unique functionality or to aggregate other services' functionality.
Although technically not necessary, Hybris recommends implementing services in terms of interfaces.   
Services interact with other components through models

Strategies

A service may delegate parts of its tasks to smaller micro-services, called strategies. The service then serves as a kind of facade to the strategies. Clients still use the service and its stable API. But under the hood the functionality is split into multiple parts. Because these parts are smaller and very focused to their task, it is easier to adapt or replace them. Strategies therefore help to further encapsulate behavior and make it more adaptable.

DAOs
A DAO (Data Access Object) is an interface to the storage back end system. DAOs store and retrieve objects. You use DAOs to save, remove, and find models. DAOs are the place to put SQL or FlexibleSearch statements and nowhere else. This is to ensure further decoupling from the underlying storage facility. DAOs interact with services via models and with the database via FlexibleSearch and SQL statements.

Models

Models are a new way to represent Hybris items. Each model contains all item attributes from all extensions thus unifying access to an item's data. Models are generated from the type system of SAP Hybris Commerce. Furthermore they are more or less simple POJOs (Plain Old Java Objects) that can be used without any storage facility. Thus, it's pretty easy to mock them up, for example for testing and debugging.  Models are used by DAOs, services, strategies, converters, and facades.


Tuesday 2 May 2017

Hybris - Data models




  Hybris data model 

Hybris Data Models are defined in the <extension>-items.xml file of each extension. 
Data model items(entities) are defined with itemtype elements.
Each item type is consist of a Java class and database Table.
items.xml  has six different tags and should be followed by same order 

automictypes 
collections
enumtypes
maptypes
relations
itemtypes

Atomic types: The item types which are primitive data types. 
For example, integer, float, double, boolean, Strings etc. They are defined in items.xml as follows.
<atomictype class=“java.lang.String” extends=“java.lang.Object” autocreate=“true” generate=“false”/>

Collection type: They are analogue of generic types in Java. A collection is a group of similiar type item types. Like a group of language used for a particular application could be stored as LanguageList.
<collectiontype code=”LanguageSet” elementtype=”Language” autocreate=”true” generate=”true” type=”set”/>

Enum types: The group of fixed constants are defined as enums, like any other language.
<enumtype code=“OrdStatus” autocreate=“true” generate=“true”>
<value code=“OPEN”/>
<value code=“IN-PROGRESS”/>
<value code=“CLOSE”/>
</enumtype>
Itemtypes: we need to define a new item type to specifies a specific ComposedType.

<itemtype code="OFFLineProduct" extends="Product"
                                  autocreate="true" generate="true"
                                  jaloclass="org.hm.core.jalo.OFFLineProduct">
                                  
<description>OFF Line product extension that contains additional attributes for off line.</description>
<deployment table="OFFLineProducts" typecode="10100" propertytable="ProductProps"/>
        <attributes>
                <attribute qualifier="store" type="java.lang.String">
                        <description> the products  store name </description>
                        <modifiers read="true" write="true" search="true" optional="false"/>
                        <persistence type="property" />
                </attribute>
                <attribute qualifier="intime" type="java.util.Date">
                        <description> the time stamp of the product  in </description>
                        <modifiers read="true" write="true" search="true" optional="false"/>
                        <persistence type="property" />
                </attribute>
                <attribute qualifier="outtime" type="java.util.Date">
                <description> the time stamp of the product  out </description>
                <modifiers read="true" write="true" search="true" optional="false"/>
                <persistence type="property" />
                </attribute>
        </attributes>
</itemtype>

Here we defined a new item type extending parent item or Generic item. 
GenericItem extends LocalizableItem extends ExtensibleItem extends Item
The jalo class, is the module class which creates the item. This class is auto generated. when you run ant build
Each of the characteristics of an item type is defined as attribute of item type. The attribute itself could be of any type.

autocreate - If 'true', the item will be created during initialization. Default is 'true'.
generate - If true, it generates constants for enum  and source code for item, it has no effect in automictypes,collections, maptype and relations.

attributes - Defines the list of item attributes.

read – If false, we cannot read this attribute, Defines if this attribute is readable or not.
write – If false,  we cannot write this attribute, Defines if this attribute is writable or not.
optional– if false, it is mandatory to initialize this attribute. Since it is not optional.
unique– if true, the attribute must hold a unique value. Similar to unique constraints in DBMS.
search – if true, the attribute is searchable through queries

persistence -
Defines how the values of the attribute will be stored. Possible values:  'property' (persistent), 'dynamic' (not persisted).

defaultvalue -Configures a default value for this attribute used if no value is provided. 

maptype: Like the java collection framework, a type, which defines map objects. 
<maptype code="localized:java.lang.String"
               argumenttype="Language"
               returntype="java.lang.String"
               autocreate="true"
               generate="false"/>

relationtype:
A RelationType defines a n-m or 1-n relation between types.

<relation code="OrderDiscountRelation" autocreate="true" generate="false" localized="false"
                deployment="de.hybris.platform.persistence.link.OrderDiscountRelation">
         <sourceElement qualifier="orders" type="AbstractOrder" cardinality="many" ordered="false">
            <modifiers read="true" write="true" search="true" optional="true"/>
         </sourceElement>
         <targetElement qualifier="discounts" type="Discount" cardinality="many" ordered="true" collectiontype="list">
            <modifiers read="true" write="true" search="true" optional="true"/>
         </targetElement>
      </relation>

Saturday 22 April 2017

Create and Sync Product Catalog from HMC

Create Product Catalog

Login to hmc with admin/nimda
localhost:9001/hmc

Right click on Catalogs and create Catalog













Provide required fields(ID and Name)
Create 2 catalog versions - Staged and Online - Make sure Online versions as active and save












Right click on Categories and create Category
Provide Identifier and Name fields
Select Catalog version as Catalog-Staged(Electronics-Staged) and Create.















Create another Category as Computers & Accessories














Create Category as Smartphones and Supercategories(Category system tab) as Mobiles & Tablets














Create Category as Tablets and Supercategories(Category system tab) as Mobiles & Tablets














Create Category as Smartphones and Supercategories(Category system tab) as Mobiles & Tablets



Create Category as Accessories and Supercategories(category system tab) as Mobiles & Tablets

Create Category as Desktops & Monitors and Supercategories(category system tab) as Computers & Accessories














Create Category as Laptops and Supercategories as Computers & Accessories

Create Category as Hard Drives and Supercategories as Computers & Accessories

Repeat the above steps to create more categories/sub categories.

Catalog, versions, categories, sub categories are ready.
We can see complete Catalog and categories hierarchic.















Right click on Catalogs and create Catalog














Provide Code, name, Catalog version, super category (Category system tab) etc to create product















Repeat the above step to create Lenovo-k2 and Lenovo-k3 products.




Provide Code, name, Catalog version, super category to create Dell XPS 1, Dell XPS  2, Dell XPS 3 products.















Repeat the above steps to create more products

Catalog, versions, categories, sub categories and products are ready.


We can see complete products hierarchic.














Create media. For this, right click on media in multimedia folder
Upload the required image and assign this media to product.

Create and assign the variants, click on the product variants tab.
Right click on the variants section and create the variants.















Repeat the above steps to create variants on other products.
Product Catalog structure for staged version is ready














Sync Catalog Staged to Online

Sync your data from staged to online, open your staged version and click on Catalog version tab















Create Synchronization on Dependent Catalog Version














Select Synchronization target as Online version and save














Click on Synchronize Catalog Version














Select Staged Version and click on start















After completing click on done.

















We can see complete Staged and Online products hierarchic.