The Creation of Comparison Table
The creation of comparison table in Financial Services Accelerator consists of several parts that can be analyzed from two main perspectives - WCMS aspect (CMS Data Model) and underlying logic (Java / Spring).
WCMS Aspect
The CMSMultiComparisonTabContainer component is available from the category page. The container can hold one or several CMSComparisonTabComponent components. Each CMSComparisonTabComponent has a specific ComparisonPanelCMSComponent associated with it.
Class Diagram
The complexity of relations can be seen on the category page of travel insurance, where we have several tabs with relevant content.
Creating a New Component Through an ImpEx File
The new CMSMultiComparisonTabContainer can be created by using an ImpEx file. The required ImpEx can be appended to a cms-content.impex file or a customized ImpEx file under the project resources' import directory. For example, <HYBRIS_BIN_DIR> \modules\financial-services-accelerator\financialstore\resources\financialstore\import\sampledata\contentCatalogs\financialContentCatalog\insurance-cms-responsive-content.impex.
# Comparison panel CMS components INSERT_UPDATE ComparisonPanelCMSComponent; $contentCV[unique = true]; uid[unique = true]; name; visible; &componentRef; products(code, $productCV) ; ; singleTripComparisonPanel ; Single Trip comparison panel ; true ; singleTripComparisonPanel ; TRA_SINGLE_BUDGET,TRA_SINGLE_SILVER,TRA_SINGLE_GOLD ; ; annualTripComparisonPanel ; Annual Trip comparison panel ; true ; annualTripComparisonPanel ; TRA_ANNUAL_BUDGET,TRA_ANNUAL_SILVER,TRA_ANNUAL_GOLD ; ; backpackingTripComparisonPanel ; Backpacking Trip comparison panel ; true ; backpackingTripComparisonPanel ; TRA_BACKPACKERS_BUDGET,TRA_BACKPACKERS_SILVER,TRA_BACKPACKERS_GOLD # CMS comparison tabs components INSERT_UPDATE CMSComparisonTabComponent; $contentCV[unique = true]; uid[unique = true]; name; visible; &componentRef; comparisonPanel(&componentRef); imageComponent(&componentRef) ; ; singleTripComparisonTab ; Single Trip comparison tab ; true ; singleTripComparisonTab ; singleTripComparisonPanel ; insuranceSingleTabImage ; ; annualTripComparisonTab ; Annual Trip comparison tab ; true ; annualTripComparisonTab ; annualTripComparisonPanel ; insuranceAnnualTabImage ; ; backpackingTripComparisonTab ; Backpacking Trip comparison tab ; true ; backpackingTripComparisonTab ; backpackingTripComparisonPanel ; insuranceBackpackTabImage INSERT_UPDATE CMSMultiComparisonTabContainer; $contentCV[unique = true]; uid[unique = true]; name; visible; simpleCMSComponents(uid, $contentCV); &componentRef ; ; TravelMultiComparisonTabContainer ; Comparison Tab container ; true ; singleTripComparisonTab,annualTripComparisonTab,backpackingTripComparisonTab ; TravelMultiComparisonTabContainer
Rendering Components
|
Component |
JSP View |
Renderer (Spring Bean ID) |
|---|---|---|
|
CMSMultiComparisonTabContainer |
cmsmulticomparisontabcontainer.jsp
|
/ |
|
CMSComparisonTabComponent |
cmscomparisontabcomponent.jsp
|
cmsComparisonTabComponentRenderer
|
|
ComparisonPanelCMSComponent |
comparisonpanelcmscomponent.jsp
|
comparisonPanelCMSComponentRenderer
|
Underlying Logic
The underlying implementation consists of three major aspects - price population, assembly of comparison table and the UI representation (JSP view). The first part (price population) is covered in Quotation Engine. For the other two aspects, please read the following sections.
The Assembly of ComparisonTable Object
The custom tag (productComparisonItem.tag) builds up a comparison table from the searchPageData that has been passed. The productComparisonItem.tag tag belongs to the custom tag library (financialtags.tld) with the tag class or handler being InsuranceComparisonTag.java.
<financialtags:comparisonTable searchPageData="${searchPageData}" tableFactory="insuranceComparisonTableFactory" var="comparisonTable"/>
searchPageData
The searchPageData is a Spring MVC Model attribute, provided by ComparisonPanelCMSComponentRenderer. This model attribute holds a collection of converted products (ProductDataobjects) that have been assigned to ComparisonPanel component.
tableFactory
<alias name="defaultInsuranceComparisonTableFactory" alias="insuranceComparisonTableFactory"/>
<bean id="defaultInsuranceComparisonTableFactory" class="de.hybris.platform.financialacceleratorstorefront.comparison.InsuranceComparisonTableFactory">
<property name="billingTimeDataComparator" ref="billingTimeDataComparator"/>
<property name="excludableBillingEvents">
<set>
<value>paynow</value>
</set>
</property>
<property name="priceFactory" ref="priceDataFactory"/>
</bean>
<alias name="defaultBillingTimeDataComparator" alias="billingTimeDataComparator" /> <bean id="defaultBillingTimeDataComparator" class="de.hybris.platform.financialfacades.util.BillingTimeDataComparator"> <property name="top" value="paynow" /> <property name="bottom" value="deductible" /> </bean>
Simply put, you would need to supply SearchPageData to the custom tag (productComparisonItem.tag), whose handler (InsuranceComparisonTag) then tries to invoke the provided table factory (InsuranceComparisonTableFactory, in this case) and prepare the data for the page. This means that the whole creation logic is delegated to the comparison table factory, which leaves room for different implementation if needed, as long as the object returned is of type ComparisonTable.
The Implementation of InsuranceComparisonTableFactory
The InsuranceComparisonTableFactory implements ComparisonTableFactory interface and a mandatory method (createTable), which accepts SearchPageData of a type ProductData.
- Get the list of main products:
This step ensures that the products that are added to the comparison panel component are all part of the same bundle and are able to provide the prices.
- Collect the BillingEvent (BE) and OneTimeChargeEntry Objects (OTCE)
- Loop through the list of Products
- Get the SubscriptionPricePlan of the Product
- Loop through the OneTimeChargeEntry collection of the price plan:
- [if the billing event associated with the charge entry is not excluded] -> put the BillingEvent into a Set<BillingTimeData> (BE Set)
- [if the billing event associated with the charge entry is not excluded] -> put the OneTimeChargeEntry into a Map<BillingEvent.code, OneTimeChargeEntryData> (OTCE Map)
- Add the OTCE Map to a new Map<ProductData, OTCE Map>
- The complex object Map<ProductData, OTCE Map> is going to be used to set up a column in step 4
- Loop through the list of Products
- Set up 1st column - billing event / label column (providing the labels)
This step simply creates a ComparisonTableColumn and adds the contents of BE Set
- Set up remaining columns - product-specific columns (providing the values)
-
Loop through the list of Products
- Create a ComparisonTableColumn for the product
- Get OTCE Map from Map<ProductData, OTCE Map> for the current product
- Loop through the BE Set
-
Get the matching OneTimeChargeEntry from the OTCE Map based on the code of billing event
- Add it as an Item of the ComparisonTableColumn
-
As a result, n-number of columns have been created (based on the number of products supplied)
-
- Return the ComparisonTable object
In the first step, we use the method getMainProducts to display the products inside ComparisonPanelCMSComponent. The searchPageData represents all products that you can add to the selected ComparisonPanelCMSComponent (this is being done through the cms-responsive-content.impex file of the banking or insurance content catalog). The method getMainProducts filters the searchPageData, so that only main products are returned. This means that if we add an optional product to ComparisonPanelCMSComponent, that product is not going to be displayed in the comparison table.
UI Representation
- Render the image first, if any
- Render the whole label column (top-bottom approach).
For the rendering, ComparisonTableColumn that holds billing events is used.
- Render each product column (whole, top-bottom approach).
Separate tag is used for the display (productComparisonItem.tag). To this tag, several values are supplied comparisonTable.columns of the current comparison table (both key - representing a product in this iteration and value - representing the OneTimeChargeEntry collection).
<c:forEach items="${comparisonTable.columns}" var="columnTable"> <c:if test="${columnTable.key.getClass().name =='de.hybris.platform.commercefacades.product.data.ProductData'}"> <div class="products__item"> <product:productListerGridItem comparisonTable="${comparisonTable}" comparisonTableColumn="${columnTable.value}" product="${columnTable.key}" hideOptionProducts="${hideOptionProducts}" addToCartBtn_label_key="${addToCartBtn_label_key}"/> </div> </c:if> </c:forEach>- Display price information, as well as optional products list (in case of event insurance)
- Display appropriate button for add to cart logic and checkboxes for optional products, if needed
Depending on a type of the product, this button is displayed as a Choose a Product button (configurable products) or Select button (non-configurable products).
Different logic is applied for different types of products:- Configurable products: the button leads to product configuration page (banking)
- Non-configurable products: the button adds the product to the cart (insurance)
- Display OneTimeChargeEntry objects (looping through the collection of oneTimeChargeEntry objects)
For more information on displaying OneTimeChargeEntry objects, see Data Model Enhancements and Related Features.
Displaying Optional Products
To display optional products within the comparison table, as is implemented for event insurance product, you need to set the attribute hideOptionProducts to false in the related JSP file (for example, eventInsurancesPage.jsp).
<div class="col-xs-12">
<div id="tab_content" class="comparison-table comparison-table__body">
<cms:pageSlot position="ImageSlot" var="component" />
<product:productComparison columns="4" searchPageData="${searchPageData}" imageComponent="${component}" hideOptionProducts="false" addToCartBtn_label_key="basket.add.to.basket.getaquote" />
</div>
</div>
<financialCart:changePlanConfirmPopup confirmActionButtonId="addNewPlanConfirmButton" cartData="${cartData}"/>
</div>