Skip to main content

Enabling Inventory index for storefront in Websphere Commerce


By default, Inventory Index is only meant for business users to use in CMC for Product Ranking and merchandising purpose. This document describes how to enable this OOTB SOLR Index for Store Front usage so that it can be used to get SKUs Inventory from SOLR Index instead of DB hits.

The implementation involves two steps:
  1. Enable OOTB Inventory Index
  2. Make it usable by Store Front Pages

Enable Inventory Index


This step is well described at Infocenter at Setting up and building the inventory index



Enable Inventory Index for Store Front pages


This involves following steps

  1. Define a Search resource Handler to accept Inventory fetch requests.
  2. SOLR Index Customization, if required
  3. Define a search Profile to expose Inventory Schema fields to Response
  4. Map SOLR schema fields to External Response fields
  5. Custom Expression Provider to get default fulfillment center Id.
  6. Create a new SOLR Search Post Processor to format the solr fields in Response ready format.

Inventory Search Resource Handler

A new search resource handler needs to be mapped with a unique path using which a REST service can be invoked from Store Front Pages..

Handler: XInventorySearchResourceHandler
Extends: AbstractSearchResourceHandler

Class level path annotation: @Path ("store/{storeId}/inventoryview")
Method level path annotation: @Path ("byCatentryId/{catentryId}")

@GET
@Path("byCatentryId/{catentryId}")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response fetchInventoryStatusByCatalogEntryId(
        @QueryParam("responseFormat") String responseFormat,
        @PathParam("storeId") String storeId,
        @PathParam("catentryId") String catentryId,
        @QueryParam("searchProfile") String searchProfile) {
     
    Response result = null;
    SearchCriteria searchCriteria = null;

    try {
        searchCriteria = prepareSearchCriteria(storeId, null, "inventoryview",
            "store/10501/inventoryview/byCatentryId/{catentryId}", searchProfile);
         
        throwRestExceptionIfErrorsAreDetected();
        searchCriteria.setControlParameterValue(
                "_wcf.search.internal.optional.query",
                "catentry_id:" + catentryId);

        result = performSearch(searchCriteria);
    } catch (Exception e) {
        result = generateResponseFromRespData(searchCriteria, null, e);
    } // EndTryCatch

    LOGGER.debug("Exit");
    return result;

} //EndMethod

Search Profile for Inventory Index


<!-- Search Profile to get Inventory SOLR response for a given catentryId -->
<_config:profile indexName="Inventory" name="X_findInventoryByCatentryId">
    <_config:query>
        <_config:param name="maxRows" value="50" />
        <_config:param name="maxTimeAllowed" value="15000" />
         
        <!--Add Providers -->
         
        <!--Add Post Processors -->
    </_config:query>
    <_config:result>
        <_config:field name="catentry_id"/>
        <_config:field name="inv_strlocqty_*"/>
        <_config:field name="inv_inventoryflag_*"/>
    </_config:result>
</_config:profile>

Comments

Popular posts from this blog

Auto Suggestion in Websphere Commerce Search

There are two types of auto suggestions..  1) Suggest keywords based on Search term. 2) Suggest actual Entity based on Search term. The Auto-Suggestion feature is now handled via Search Rest calls in FEP8. Technically it is Term Search for Spellcheck fields. So the whole thing can be summarized as below mentioned steps: /conf/solrconfig.xml Configure request handler for  /terms  URL Configure  wc_textSuggest  and  wc_spellCheck  configuration /conf/schema.xml Define SOLR fields that are too be shown as Auto Suggested keywords when searched for Terms Define Spell check fields which are to be spell corrected for showing suggestions SOLR Configuration Changes   As auto suggested keywords are nothing but different Terms that are being Indexed at the time of commit, we need to define a handler in solrconfig.xml. <!--          WebSphere Commerce terms request han...

Websphere Commerce "too many boolean clauses" problem

Sometimes in large scale applications, Store encountered error message is shown on Product Listing page. Root cause: On PLP, sometimes we need to show some information which can be derived from associate SKUs, like color swatches etc. While getting these information from Index, SOLR needs to build the query with product SKU information. When a product is too many SKUs, the parsing fails and we do see error message like below: SolrCore      E org.apache.solr.common.SolrException log org.apache.solr.common.SolrException: org.apache.lucene.queryParser.ParseException: Cannot parse 'catentry_id:(87765 "87766" "87767" "87768" ... ...)':  too many boolean clauses Solution: SOLR has a default maxBoolean configuration which is 3072. Look for the < maxBooleanClauses >  attribute in solrconfig.xml and increase it to appropriate value to handle your catalog structure.

Websphere Commerce Creating a custom SOLR core

This page describes how we can create custom SOLR cores in commerce. Let's think of a e commerce site where we retailers can log in and can register there shops. We want to index Shops so that user can search for different shops. SOLR Core Naming Convention A custom SOLR core has to be named according to OOTB convention  MC_10001_<coreName>_en_US . The core name should be a single word without any underscores in it. An entry in solr.xml will look like as below < core   instanceDir = "MC_10001\en_US\Shops\"   name = "MC_10001_Shops_en_US"   /> Registering custom core with Search server Create a new folder along with the other SOLR cores,  "Shops " at /search/solr/home/MC_10001/en_US/ Shops  should have a " conf " folder for configuration XMLs . Define SQL in /conf/wc-data-config.xml and map the database fields with SOLR fields. Define SOLR fields in schema.xml We need to register our custom SO...