Thursday, May 7, 2015

Read the contract Price from solr index issue in B2B store

1.If we setup the B2B store contract model, When we try to use the contract price from indexing, it will show price pending.
2.To fix the issue, extends the SolrRESTSearchCatalogEntryViewPriceQueryPostprocessor class

3.Override the applyFieldNamingPattern mathod.

4.Instead of get the contractId value from SelectionCriteria  to get it from solr parameter "_wcf.search.contract".

Sample Code below:

protected List<String> applyFieldNamingPattern(String origFieldName,
            String currencyCode) {
        String METHODNAME = "applyFieldNamingPattern(String origFieldName String currencyCode)";
        if(LoggingHelper.isEntryExitTraceEnabled(LOGGER))
            LOGGER.entering(CLASSNAME, "applyFieldNamingPattern(String origFieldName String currencyCode)", new Object[] {
                origFieldName, currencyCode
            });
        ArrayList fieldNameWithPattern = new ArrayList();
        if(origFieldName == null)
            return null;
        String storeId = getFinalControlParameterValue("_wcf.search.store.online");
        String compatiblePriceIndexMode = StoreHelper.getCompatiblePriceIndexMode(storeId);
        if(LoggingHelper.isTraceEnabled(LOGGER))
            if(compatiblePriceIndexMode != null)
                LOGGER.exiting(CLASSNAME, "applyFieldNamingPattern(String origFieldName String currencyCode)", (new StringBuilder("compatiblePriceIndexMode:")).append(compatiblePriceIndexMode).toString());
            else
                LOGGER.exiting(CLASSNAME, "applyFieldNamingPattern(String origFieldName String currencyCode)", "Not define compatiblePriceIndexMode, will use compatible mode");
        if(compatiblePriceIndexMode != null && "1.0".equals(compatiblePriceIndexMode))
        {
//String strContractId = EntitlementHelper.getFinalUsableContract((SearchCriteria)iSelectionCriteria);           
String strContractId = getControlParameterValue("_wcf.search.contract");
            List contractIdList = EntitlementHelper.getContractIdAsStringListFromString(strContractId);
            for(Iterator iterator = contractIdList.iterator(); iterator.hasNext();)
            {
                String contract = (String)iterator.next();
                String newFieldName = origFieldName.concat(currencyCode).concat("_").concat(contract);
                fieldNameWithPattern.add(newFieldName);
                if(LoggingHelper.isTraceEnabled(LOGGER))
                    LOGGER.logp(LoggingHelper.DEFAULT_TRACE_LOG_LEVEL, CLASSNAME, "applyFieldNamingPattern(String origFieldName String currencyCode)", (new StringBuilder("create new facet name with: ")).append(newFieldName).toString());
            }

        } else
        {
            String newFieldName = origFieldName.concat(currencyCode);
            fieldNameWithPattern.add(newFieldName);
            if(LoggingHelper.isTraceEnabled(LOGGER))
                LOGGER.logp(LoggingHelper.DEFAULT_TRACE_LOG_LEVEL, CLASSNAME, "applyFieldNamingPattern(String origFieldName String currencyCode)", (new StringBuilder("applied facet pattern: ")).append(newFieldName).toString());
        }
        if(LoggingHelper.isEntryExitTraceEnabled(LOGGER))
            LOGGER.exiting(CLASSNAME, "applyFieldNamingPattern(String origFieldName String currencyCode)");
        return fieldNameWithPattern;
    } 

No comments:

Post a Comment