📄 priceservices.java
字号:
Collection productIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PRODUCT_ID", "condValue", productId)); if (productIdConds != null && productIdConds.size() > 0) { Iterator productIdCondsIter = productIdConds.iterator(); while (productIdCondsIter.hasNext()) { GenericValue productIdCond = (GenericValue) productIdCondsIter.next(); productPriceRuleIds.add(productIdCond.getString("productPriceRuleId")); } } // by virtualProductId, if not null if (virtualProductId != null) { Collection virtualProductIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PRODUCT_ID", "condValue", virtualProductId)); if (virtualProductIdConds != null && virtualProductIdConds.size() > 0) { Iterator virtualProductIdCondsIter = virtualProductIdConds.iterator(); while (virtualProductIdCondsIter.hasNext()) { GenericValue virtualProductIdCond = (GenericValue) virtualProductIdCondsIter.next(); productPriceRuleIds.add(virtualProductIdCond.getString("productPriceRuleId")); } } } // by prodCatalogId - which is optional in certain cases if (UtilValidate.isNotEmpty(prodCatalogId)) { Collection prodCatalogIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_CLG_ID", "condValue", prodCatalogId)); if (prodCatalogIdConds != null && prodCatalogIdConds.size() > 0) { Iterator prodCatalogIdCondsIter = prodCatalogIdConds.iterator(); while (prodCatalogIdCondsIter.hasNext()) { GenericValue prodCatalogIdCond = (GenericValue) prodCatalogIdCondsIter.next(); productPriceRuleIds.add(prodCatalogIdCond.getString("productPriceRuleId")); } } } // by productStoreGroupId if (UtilValidate.isNotEmpty(productStoreGroupId)) { Collection storeGroupConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_SGRP_ID", "condValue", productStoreGroupId)); if (storeGroupConds != null && storeGroupConds.size() > 0) { Iterator storeGroupCondsIter = storeGroupConds.iterator(); while (storeGroupCondsIter.hasNext()) { GenericValue storeGroupCond = (GenericValue) storeGroupCondsIter.next(); productPriceRuleIds.add(storeGroupCond.getString("productPriceRuleId")); } } } // by webSiteId if (UtilValidate.isNotEmpty(webSiteId)) { Collection webSiteIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_WEBSITE_ID", "condValue", webSiteId)); if (webSiteIdConds != null && webSiteIdConds.size() > 0) { Iterator webSiteIdCondsIter = webSiteIdConds.iterator(); while (webSiteIdCondsIter.hasNext()) { GenericValue webSiteIdCond = (GenericValue) webSiteIdCondsIter.next(); productPriceRuleIds.add(webSiteIdCond.getString("productPriceRuleId")); } } } // by partyId if (UtilValidate.isNotEmpty(partyId)) { Collection partyIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PARTY_ID", "condValue", partyId)); if (partyIdConds != null && partyIdConds.size() > 0) { Iterator partyIdCondsIter = partyIdConds.iterator(); while (partyIdCondsIter.hasNext()) { GenericValue partyIdCond = (GenericValue) partyIdCondsIter.next(); productPriceRuleIds.add(partyIdCond.getString("productPriceRuleId")); } } } // by currencyUomId Collection currencyUomIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_CURRENCY_UOMID", "condValue", currencyUomId)); if (currencyUomIdConds != null && currencyUomIdConds.size() > 0) { Iterator currencyUomIdCondsIter = currencyUomIdConds.iterator(); while (currencyUomIdCondsIter.hasNext()) { GenericValue currencyUomIdCond = (GenericValue) currencyUomIdCondsIter.next(); productPriceRuleIds.add(currencyUomIdCond.getString("productPriceRuleId")); } } productPriceRules = new LinkedList(); Iterator productPriceRuleIdsIter = productPriceRuleIds.iterator(); while (productPriceRuleIdsIter.hasNext()) { String productPriceRuleId = (String) productPriceRuleIdsIter.next(); GenericValue productPriceRule = delegator.findByPrimaryKeyCache("ProductPriceRule", UtilMisc.toMap("productPriceRuleId", productPriceRuleId)); if (productPriceRule == null) continue; productPriceRules.add(productPriceRule); } } else { // this would be nice, but we can't cache this so easily... // List pprExprs = UtilMisc.toList(new EntityExpr("thruDate", EntityOperator.EQUALS, null), // new EntityExpr("thruDate", EntityOperator.GREATER_THAN, UtilDateTime.nowTimestamp())); // productPriceRules = delegator.findByOr("ProductPriceRule", pprExprs); productPriceRules = delegator.findAllCache("ProductPriceRule"); if (productPriceRules == null) productPriceRules = new LinkedList(); } // ========= go through each price rule by id and eval all conditions ========= // utilTimer.timerString("Before eval rules", module); int totalConds = 0; int totalActions = 0; int totalRules = 0; Iterator productPriceRulesIter = productPriceRules.iterator(); while (productPriceRulesIter.hasNext()) { GenericValue productPriceRule = (GenericValue) productPriceRulesIter.next(); String productPriceRuleId = productPriceRule.getString("productPriceRuleId"); // check from/thru dates java.sql.Timestamp fromDate = productPriceRule.getTimestamp("fromDate"); java.sql.Timestamp thruDate = productPriceRule.getTimestamp("thruDate"); if (fromDate != null && fromDate.after(nowTimestamp)) { // hasn't started yet continue; } if (thruDate != null && thruDate.before(nowTimestamp)) { // already expired continue; } // check all conditions boolean allTrue = true; StringBuffer condsDescription = new StringBuffer(); Collection productPriceConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("productPriceRuleId", productPriceRuleId)); Iterator productPriceCondsIter = UtilMisc.toIterator(productPriceConds); while (productPriceCondsIter != null && productPriceCondsIter.hasNext()) { GenericValue productPriceCond = (GenericValue) productPriceCondsIter.next(); totalConds++; if (!checkPriceCondition(productPriceCond, productId, prodCatalogId, productStoreGroupId, webSiteId, partyId, quantity, listPrice, currencyUomId, delegator)) { // if there is a virtualProductId, try that given that this one has failed if (virtualProductId != null) { if (!checkPriceCondition(productPriceCond, virtualProductId, prodCatalogId, productStoreGroupId, webSiteId, partyId, quantity, listPrice, currencyUomId, delegator)) { allTrue = false; break; } // otherwise, okay, this one made it so carry on checking } else { allTrue = false; break; } } // add condsDescription string entry condsDescription.append("["); GenericValue inputParamEnum = productPriceCond.getRelatedOneCache("InputParamEnumeration"); condsDescription.append(inputParamEnum.getString("enumCode")); // condsDescription.append(":"); GenericValue operatorEnum = productPriceCond.getRelatedOneCache("OperatorEnumeration"); condsDescription.append(operatorEnum.getString("description")); // condsDescription.append(":"); condsDescription.append(productPriceCond.getString("condValue")); condsDescription.append("] "); } // add some info about the prices we are calculating from condsDescription.append("[list:"); condsDescription.append(listPrice); condsDescription.append(";avgCost:"); condsDescription.append(averageCost); condsDescription.append(";margin:"); condsDescription.append(margin); condsDescription.append("] "); boolean foundFlatOverride = false; // if all true, perform all actions if (allTrue) { // check isSale if ("Y".equals(productPriceRule.getString("isSale"))) { isSale = true; } Collection productPriceActions = delegator.findByAndCache("ProductPriceAction", UtilMisc.toMap("productPriceRuleId", productPriceRuleId)); Iterator productPriceActionsIter = UtilMisc.toIterator(productPriceActions); while (productPriceActionsIter != null && productPriceActionsIter.hasNext()) { GenericValue productPriceAction = (GenericValue) productPriceActionsIter.next(); totalActions++; // yeah, finally here, perform the action, ie, modify the price double modifyAmount = 0; if ("PRICE_POD".equals(productPriceAction.getString("productPriceActionTypeId"))) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -