我正在使用ATG 9.4并尝试修改促销引擎,以便我们可以为每个促销设置过滤器属性,而不是直接在全局QualifierService上设置。

基本上,我所做的就是为QualifierService上可用的每个过滤器标记的属性添加到Item Discount存储库项目中。然后,我将ItemDiscountCalculator子类化,并覆盖了priceItems()。我从pPricingModel中读取了标志,构造了一个新的Qualifier对象,并使用项ItemDiscountCalculator.EXTRA_PARAM_QUALIFIERSERVICE将其放入pExtraParameters映射中。然后,我调用super.priceItems()

这对于我要尝试的工作而言100%完美-但是,当我构造新的Qualifier时,我使用setLoggingXXX方法来反映全局QualifierService上的级别,但是这些新对象没有日志记录。

我认为这与将对象注册到核有关,因此与它使用的任何日志记录组件有关,但是我无法找到注册它们所需的操作,或者至少不允许Qualifier进行自然日志记录。

以下是相关的代码行:

@Override
@SuppressWarnings("unchecked")
public void priceItems(List pPriceQuotes, List pItems, RepositoryItem pPricingModel, Locale pLocale, RepositoryItem pProfile, Order pOrder, Map pExtraParameters) throws PricingException {
    if (isLoggingTrace())
        logTrace("Entry - CustomItemDiscountCalculator.priceItems()");

    Qualifier qualifierService = getQualifierService(pPricingModel);

    if (pExtraParameters == null) {
        pExtraParameters = new HashMap();
    }

    pExtraParameters.put(ItemDiscountCalculator.EXTRA_PARAM_QUALIFIERSERVICE, qualifierService);

    super.priceItems(pPriceQuotes, pItems, pPricingModel, pLocale, pProfile, pOrder, pExtraParameters);

    if (isLoggingTrace())
        logTrace("Exit - CustomItemDiscountCalculator.priceItems()");
}

private Qualifier getQualifierService(RepositoryItem pPricingModel) {
    if (isLoggingTrace())
        logTrace("Entry - CustomItemDiscountCalculator.getQualifierService()");

    Qualifier qualifierService = new Qualifier();

    /* Get global component at /atg/commerce/pricing/QualifierService */
    Qualifier defaultQualifierService = getQualifierService();

    /* Shallow clone the global QualifierService component */
    qualifierService.setPMDLCache(defaultQualifierService.getPMDLCache());
    qualifierService.setClosenessQualifierItemDescriptorName(defaultQualifierService.getClosenessQualifierItemDescriptorName());
    qualifierService.setExactlyPromotionLoopThrough(defaultQualifierService.isExactlyPromotionLoopThrough());
    qualifierService.setLoggingDebug(defaultQualifierService.isLoggingDebug());
    qualifierService.setLoggingError(defaultQualifierService.isLoggingError());
    qualifierService.setLoggingInfo(defaultQualifierService.isLoggingInfo());
    qualifierService.setLoggingTrace(defaultQualifierService.isLoggingTrace());
    qualifierService.setLoggingWarning(defaultQualifierService.isLoggingWarning());
    qualifierService.setNucleus(defaultQualifierService.getNucleus());
    qualifierService.setPricingModelProperties(defaultQualifierService.getPricingModelProperties());
    qualifierService.setPricingModelRepository(defaultQualifierService.getPricingModelRepository());
    qualifierService.setServiceInfo(defaultQualifierService.getServiceInfo());

    /* Set any promotion specific qualifier properties */
    Boolean curFilterValue;
    if (isLoggingDebug()) {
        logDebug("Setting qualifier properties for promo: " + pPricingModel);
    }

    curFilterValue = (Boolean) pPricingModel.getPropertyValue("filterForQualifierDiscountedByAnyDiscountId");
    qualifierService.setFilterForQualifierDiscountedByAnyDiscountId(curFilterValue);

    // ... copy the rest of the QualifierService filters

    if (isLoggingTrace())
        logTrace("Exit - CustomItemDiscountCalculator.getQualifierService()");
    return qualifierService;
}

最佳答案

LogListener[] logListeners = defaultQualifierService.getLogListeners();
for (LogListener[] logListener : logListeners) {
    qualifierService.addLogListener(logListener);
}

10-06 02:22