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.

The following insurance-cms-responsive-content.impex example shows how to create and add the multi-tab component to the page content slot.
# 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

Each of the components mentioned above has a corresponding JSP view. Some components have a specific renderer associated with them as well, as you can see from the following table.

Component

JSP View

Renderer (Spring Bean ID)

CMSMultiComparisonTabContainer

cmsmulticomparisontabcontainer.jsp
  • Displays the child tab components (CMSComparisonTabComponent)
  • Adds wrappers around the tab components and checks several conditions before displaying the content of a tab component

/

CMSComparisonTabComponent

cmscomparisontabcomponent.jsp
  • Displays the associated comparison panel component (ComparisonPanelCMSComponent) and adds a wrapper element

cmsComparisonTabComponentRenderer
  • Substitutes the location where SAP Commerce should look for the JSP file (the default behavior is that the JSP view is searched in the same extension where the ItemType of that component has been defined (financialservices). The renderer replaces financialservices with financialacceleratorstorefront extension). Other than that, no custom logic.

ComparisonPanelCMSComponent

comparisonpanelcmscomponent.jsp
  • Invokes a separate tag (productListerGrid.tag), which renders and displays the table content. For more information, see the following section.
    <product:productListerGrid columns="4" searchPageData="${searchPageData}" hideOptionProducts="true" addToCartBtn_label_key="basket.add.to.basket.select" />
comparisonPanelCMSComponentRenderer
  • Replaces the location where SAP Commerce should look for the JSP file, and overrides the getVariablesToExpose method.

  • This method provides one crucial input for generation of comparison table- searchPageData, of the type ProductCategorySearchPageData<SearchStateData, ProductData, CategoryData>. This object contains the information about the product price although the product has not been added to the cart.
  • For converting the data, it uses the comparisonPanelProductConverter, that converts the products associated with this component through an ImpEx (data model).
    @Override
    protected Map<String, Object> getVariablesToExpose(final PageContext pageContext, final C component)
    {
       final Map<String, Object> variables = super.getVariablesToExpose(pageContext, component);
      
       final ProductCategorySearchPageData<SearchStateData, ProductData, CategoryData> searchPageData = new ProductCategorySearchPageData<>();
       searchPageData.setResults(Converters.convertAll(component.getProducts(), getProductConveter()));
       variables.put("searchPageData", searchPageData);
      
       final ProductCategorySearchPageData<SearchStateData, ProductData, CategoryData> mandatoryOptionProductsData = new ProductCategorySearchPageData<>();
       mandatoryOptionProductsData.setResults(Converters.convertAll(component.getMandatoryBundleProducts(), getProductConveter()));
       variables.put("mandatoryOptionProducts", mandatoryOptionProductsData);
      
       return variables;
    }
  • This converter has one important populator - productQuotationPricePopulator that populates the quotation prices for a specific product, based on quotation engine. For more information on the pricing logic, see Quotation Engine.

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.

The custom tag is invoked in productComparisonItem.tag, where the required attributes are supplied:
<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

The tableFactory is a reference to a Spring bean, currently defined in financialacceleratorstorefront-spring.xml (see the following code example).
<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>
This bean references billingTimeDataComparator, which is defined in financialfacades-spring.xml and is used to compare two billing times (that is, two billing events). If the BillingTime code matches either the top or bottom attribute value, it will put the BillingTime in one of these places. Otherwise, it will perform a comparison based on the BillingTime name.
<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 logic in productListerGrid.tag currently relies on a specific implementation of InsuranceComparisonTableFactory. In the following sub-section, we examine this logic in more details.

The Implementation of InsuranceComparisonTableFactory

The InsuranceComparisonTableFactory implements ComparisonTableFactory interface and a mandatory method (createTable), which accepts SearchPageData of a type ProductData.

The procedure for creating a comparison table consists of several steps:
  1. 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.

  2. 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
  3. Set up 1st column - billing event / label column (providing the labels)

    This step simply creates a ComparisonTableColumn and adds the contents of BE Set

  4. 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)

  5. 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.

In the current implementation of Financial Services Accelerator, all added products belong to the same (root) bundle template. By using the method getMainProductsFromDifferentBundles, you can add products from different bundles, but they need to belong to the same root bundle (e.g. travel insurance).

UI Representation

When the comparison table is generated, it is placed inside the variable called comparisonTable. The current implementation works in the following way:
  1. Render the image first, if any
  2. Render the whole label column (top-bottom approach).

    For the rendering, ComparisonTableColumn that holds billing events is used.

  3. 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>
    1. Display price information, as well as optional products list (in case of event insurance)
    2. 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)
    3. 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>