Author: sichen
Date: Thu Jul 20 16:39:46 2006 New Revision: 424117 URL: http://svn.apache.org/viewvc?rev=424117&view=rev Log: Removed old marketing package auto-explode code which has now been replaced by BOM-based code for new the Marketing Package product type Modified: incubator/ofbiz/trunk/applications/ecommerce/data/DemoProduct.xml incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java incubator/ofbiz/trunk/applications/product/data/ProductTypeData.xml Modified: incubator/ofbiz/trunk/applications/ecommerce/data/DemoProduct.xml URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/ecommerce/data/DemoProduct.xml?rev=424117&r1=424116&r2=424117&view=diff ============================================================================== --- incubator/ofbiz/trunk/applications/ecommerce/data/DemoProduct.xml (original) +++ incubator/ofbiz/trunk/applications/ecommerce/data/DemoProduct.xml Thu Jul 20 16:39:46 2006 @@ -228,17 +228,7 @@ <ProductPrice productId="GZ-DIG" productPricePurposeId="PURCHASE" productPriceTypeId="DEFAULT_PRICE" currencyUomId="USD" productStoreGroupId="_NA_" fromDate="2001-05-13 12:00:00.0" price="55.99" createdDate="2001-05-13 12:00:00.0" createdByUserLogin="admin" lastModifiedDate="2001-05-13 12:00:00.0" lastModifiedByUserLogin="admin"/> <ProductPrice productId="GZ-DIG" productPricePurposeId="PURCHASE" productPriceTypeId="LIST_PRICE" currencyUomId="USD" productStoreGroupId="_NA_" fromDate="2001-05-13 12:00:00.0" price="80.0" createdDate="2001-05-13 12:00:00.0" createdByUserLogin="admin" lastModifiedDate="2001-05-13 12:00:00.0" lastModifiedByUserLogin="admin"/> - <!-- test for marketing package and auto-exploded marketing packages --> - <Product productId="GZ-KIT" productTypeId="FINISHED_GOOD" productName="Gizmo Kit" internalName="Pre-Assembled Gizmo Kit" - description="Pre-Assembled Gizmo Kit" - longDescription="Pre-Assembled Gizmo Kit" - taxable="Y" chargeShipping="Y" autoCreateKeywords="Y" isVirtual="N" isVariant="N" /> - <ProductPrice productId="GZ-KIT" productPricePurposeId="PURCHASE" productPriceTypeId="DEFAULT_PRICE" currencyUomId="USD" productStoreGroupId="_NA_" price="150" fromDate="2001-05-13 12:00:00.0"/> - <ProductPrice productId="GZ-KIT" productPricePurposeId="PURCHASE" productPriceTypeId="LIST_PRICE" currencyUomId="USD" productStoreGroupId="_NA_" price="165" fromDate="2001-05-13 12:00:00.0"/> - <ProductAssoc productId="GZ-KIT" productIdTo="GZ-1000" productAssocTypeId="MARKETING_PACKAGE" quantity="1" fromDate="2001-05-13 12:00:00.0"/> - <ProductAssoc productId="GZ-KIT" productIdTo="GZ-1001" productAssocTypeId="MARKETING_PACKAGE" quantity="2" fromDate="2001-05-13 12:00:00.0"/> - <ProductAssoc productId="GZ-KIT" productIdTo="GZ-1004" productAssocTypeId="MARKETING_PACKAGE" quantity="3" fromDate="2001-05-13 12:00:00.0"/> - + <!-- test for marketing package --> <Product productId="GZ-BASKET" productTypeId="MARKETING_PKG_AUTO" productName="Gizmo Basket" internalName="Auto-Assembled Gizmo Basket" description="Auto-Assembled Gizmo Basket. Automatically assembled each time it's ordered." longDescription="Auto-Assembled Gizmo Basket. This item will be automatically assembled with production runs every time it's ordered, and the inventory counts for it are based on the quantity available and on hand for the component items." Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=424117&r1=424116&r2=424117&view=diff ============================================================================== --- incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original) +++ incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Thu Jul 20 16:39:46 2006 @@ -187,17 +187,6 @@ List orderItemShipGroupInfo = (List) context.get("orderItemShipGroupInfo"); List orderItemPriceInfo = (List) context.get("orderItemPriceInfos"); - // explode items which are MARKETINGG_PKG_AUTO - /* - if (!orderTypeId.equals("PURCHASE_ORDER")) { - try { - explodeMarketingPkgAutoItem(orderItems, orderAdjustments, orderItemShipGroupInfo, orderItemPriceInfo, orderTypeId, delegator, dispatcher, locale); - } catch (Exception e) { - Debug.logError(e, "Error calling explodeMarketingPkgAutoItem " + e.getMessage(), module); - return ServiceUtil.returnError("Error on exploding marketing_pkg_auto item.[" + e.toString() + "]"); - } - } - */ // check inventory and other things for each item List errorMessages = FastList.newInstance(); Map normalizedItemQuantities = FastMap.newInstance(); @@ -3419,329 +3408,6 @@ return(ServiceUtil.returnError(ex.getMessage())); } } - - - - /** deprecated - * Explodes MARKET_PKG_AUTO item by replacing it with the underlying items (productIdTo in ProductAssoc.) - * Also pro-rates the adjustments (sales tax, promotions, etc.) among the underlying items. - * If there is a price difference between the MARKET_PKG_AUTO parent item and the sum of the underlying items, - * a new OrderAdjustment, "MKTG_PKG_AUTO_ADJUST" is created, to record the difference. - * - * @param orderItems - * @param orderAdjustments - * @param orderItemShipGroupInfo - * @param orderItemPriceInfo - * @param orderTypeId - * @param delegator - * @param dispatcher - * @param locale - */ - public static void explodeMarketingPkgAutoItem(List orderItems, List orderAdjustments, List orderItemShipGroupInfo, List orderItemPriceInfo, String orderTypeId, - GenericDelegator delegator, LocalDispatcher dispatcher, Locale locale) throws Exception { - - Debug.logWarning("explodeMarketingPkgAutoItem is deprecated and will be removed. Use productTypeId=MARKETING_PKG_AUTO and assocTypeId=MANUF_COMPONENT instead!", module); - List newOrderItems = new ArrayList(); - List newOrderAdjustments = new ArrayList(); - List newOrderItemShipGroupInfo = new ArrayList(); - Iterator itemIter = orderItems.iterator(); - - // loop through all order items to see if the need to be "exploded" - while (itemIter.hasNext()) { - GenericValue orderItem = (GenericValue) itemIter.next(); - String productId = orderItem.getString("productId"); - Double quantity = orderItem.getDouble("quantity"); - Double unitPrice = orderItem.getDouble("unitPrice"); - String orderItemSeqId = orderItem.getString("orderItemSeqId"); - String prodCatalogId = orderItem.getString("prodCatalogId"); - - // ignore order items which are not products - if (productId == null || "".equals(productId)) { - continue; - } - - // if an order item does not have a quantity, skip it - if (quantity == null) { - Debug.logWarning("Order item seq [" + orderItemSeqId + "] has a null quantity, so it cannot be exploded" , module); - continue; - } - - try { - //deal with the order adjustment without orderItemSeqId. These are adjustments of the order, and we just keep them. - if (orderAdjustments != null && orderAdjustments.size() > 0) { - for (int a = 0; orderAdjustments.size() > a; a++) { - GenericValue orderAdjustment = (GenericValue) orderAdjustments.get(a); - if (UtilValidate.isEmpty(orderAdjustment.getString("orderItemSeqId"))) { - newOrderAdjustments.add(orderAdjustment); - }//if - }//for - }//if - - //deal with the item ship group without orderItemSeqId. Similarly, just keep these - if (orderItemShipGroupInfo != null && orderItemShipGroupInfo.size() > 0) { - Iterator osiInfos = orderItemShipGroupInfo.iterator(); - while (osiInfos.hasNext()) { - GenericValue valueObj = (GenericValue) osiInfos.next(); - if ("OrderAdjustment".equals(valueObj.getEntityName()) || "OrderItemShipGroupAssoc".equals(valueObj.getEntityName())) { - if (UtilValidate.isEmpty(valueObj.getString("orderItemSeqId"))) { - newOrderItemShipGroupInfo.add(valueObj); - }//if - } else { - newOrderItemShipGroupInfo.add(valueObj); - }//if - }//while - }//if - - // find the products which are components of a MARKETING_PKG_AUTO, if any, for this product - List productAssocList = null; - Map tmpResult = dispatcher.runSync("getAssociatedProducts", UtilMisc.toMap("productId", productId, "type", "MARKETING_PKG_AUTO")); - if (tmpResult.get("assocProducts") != null) { - productAssocList = (List) tmpResult.get("assocProducts"); - } - - if (productAssocList != null && productAssocList.size() > 0) { - Debug.logInfo("The product [" + productId + "] explodes to [" + productAssocList.toString() + "]", module); - // now add the associated products to the order - List assocOrderItems = new ArrayList(); - double sumSubItemsPrice = 0; - double sumAssocQty = 0; - for (int i = 0; productAssocList.size() > i; i++) { - GenericValue productAssoc = (GenericValue) productAssocList.get(i); - GenericValue productTo = productAssoc.getRelatedOne("AssocProduct"); - String productIdTo = productTo.getString("productId"); - String itemDescription = ""; - - Double productToQuantity = productAssoc.getDouble("quantity"); - - if (productToQuantity == null) { - productToQuantity = new Double(1.0); - Debug.logWarning("For order item [" + orderItemSeqId + "] Product association [" + productAssoc + "] had a null quantity, assuming 1", module); - } - - Double newQuantity = new Double(productToQuantity.doubleValue() * quantity.doubleValue()); - - Double listPrice = new Double(0); - Double basePrice = new Double(0); - - // get the product name - if (productTo != null) { - itemDescription = ProductContentWrapper.getProductContentAsText(productTo, "PRODUCT_NAME", locale); - // if the product name is null or empty, see if there is an associated virtual product and get the productName of that product - if (UtilValidate.isEmpty(itemDescription)) { - GenericValue parentProduct = ProductWorker.getParentProduct(productIdTo, delegator); - if (parentProduct != null) { - itemDescription = ProductContentWrapper.getProductContentAsText(parentProduct, "PRODUCT_NAME", locale); - }//if - }//if - }//if - - // calculate price of the associated (component) product using calculateProductPrice - try { - Map priceContext = new HashMap(); - priceContext.put("product", productTo); - priceContext.put("prodCatalogId", prodCatalogId); - priceContext.put("quantity", newQuantity); - Map priceResult = dispatcher.runSync("calculateProductPrice", priceContext); - if (ModelService.RESPOND_ERROR.equals(priceResult.get(ModelService.RESPONSE_MESSAGE))) { - Debug.logWarning("There was an error while calculating the price: " + priceResult.get(ModelService.ERROR_MESSAGE), module); - }// if - - Boolean validPriceFound = (Boolean) priceResult.get("validPriceFound"); - if (!validPriceFound.booleanValue()) { - Debug.logWarning("Could not find a valid price for the product with ID [" + productIdTo + "], not adding to cart.", module); - }// if - - if (priceResult.get("listPrice") != null) { - listPrice = (Double) priceResult.get("listPrice"); - }// if - if (priceResult.get("price") != null) { - basePrice = (Double) priceResult.get("price"); - }// if - } catch (Exception e) { - Debug.logWarning(e, "There was an error while calculating the price", module); - throw e; - }// try - Debug.logInfo("The product [" + productIdTo + "] Price [" + basePrice + "]", module); - - // used to tally up total price of component items, so as to calculate correct adjustment later - sumSubItemsPrice = sumSubItemsPrice + newQuantity.doubleValue() * basePrice.doubleValue(); - sumAssocQty = sumAssocQty + productToQuantity.intValue(); - - // now create the new order item - GenericValue newOrderItem = GenericValue.create(orderItem); - newOrderItem.set("productId", productIdTo); - newOrderItem.set("quantity", newQuantity); - newOrderItem.set("unitPrice", basePrice); - newOrderItem.set("unitListPrice", listPrice); - newOrderItem.set("orderItemSeqId", orderItemSeqId + "-" + i); - newOrderItem.set("cancelQuantity", productToQuantity); - newOrderItem.set("itemDescription", itemDescription); - assocOrderItems.add(newOrderItem); - Debug.logInfo("explode OrderItem [" + orderItem.toString() + "] to [" + newOrderItem + "]", module); - }// for - - // If there were a difference between the price of the parent item and the sum of the prices of the marketing package components, - // then create an OrderAdjustment for each new order item and pro-rate the difference based on its quantity and the total quantity of all - // the component items. - double originalItemPrice = quantity.doubleValue() * unitPrice.doubleValue(); - double adjustmentPrice = originalItemPrice - sumSubItemsPrice; - if (adjustmentPrice != 0) { - for (int a = 0; assocOrderItems.size() > a; a++) { - GenericValue assocOrderItem = (GenericValue) assocOrderItems.get(a); - String assocOrderItemSeqId = assocOrderItem.getString("orderItemSeqId"); - Double productToQuantity = assocOrderItem.getDouble("cancelQuantity"); - - Double percentage = new Double(productToQuantity.doubleValue() / sumAssocQty); - Double amount = new Double(adjustmentPrice * percentage.doubleValue()); - GenericValue newOrderAdjustment = delegator.makeValue("OrderAdjustment", UtilMisc.toMap("orderAdjustmentTypeId", "MKTG_PKG_AUTO_ADJUST")); - newOrderAdjustment.put("orderItemSeqId", assocOrderItemSeqId); - newOrderAdjustment.put("amount", new Double(amount.doubleValue())); - newOrderAdjustments.add(newOrderAdjustment); - Debug.logInfo("Add new Order Adjustment [" + newOrderAdjustment.toString() + "] for Order Item [" + assocOrderItem.toString() + "]", module); - }//for - }//if - - // similarly prop-rate each order adjustment for the parent item to all the marketing package components - if (orderAdjustments != null && orderAdjustments.size() > 0) { - for (int a = 0; orderAdjustments.size() > a; a++) { - GenericValue orderAdjustment = (GenericValue) orderAdjustments.get(a); - if (orderItemSeqId.equals(orderAdjustment.getString("orderItemSeqId"))) { - Debug.log("Explode Order Adjustment [" + orderAdjustment.toString() + "]", module); - for (int b = 0; assocOrderItems.size() > b; b++) { - GenericValue assocOrderItem = (GenericValue) assocOrderItems.get(b); - String assocOrderItemSeqId = assocOrderItem.getString("orderItemSeqId"); - Double productToQuantity = assocOrderItem.getDouble("cancelQuantity"); - Double amount = orderAdjustment.getDouble("amount"); - - Double percentage = new Double(productToQuantity.doubleValue() / sumAssocQty); - amount = new Double(amount.doubleValue() * percentage.doubleValue()); - GenericValue newOrderAdjustment = GenericValue.create(orderAdjustment); - newOrderAdjustment.put("orderItemSeqId", assocOrderItemSeqId); - newOrderAdjustment.put("amount", amount); - newOrderAdjustments.add(newOrderAdjustment); - Debug.logInfo("Add new Order Adjustment [" + newOrderAdjustment.toString() + "]", module); - }//for - }//if - }//for - }//if - - // assign the new order items to the same ship group as the parent item - if (orderItemShipGroupInfo != null && orderItemShipGroupInfo.size() > 0) { - Iterator osiInfos = orderItemShipGroupInfo.iterator(); - while (osiInfos.hasNext()) { - GenericValue valueObj = (GenericValue) osiInfos.next(); - if ("OrderItemShipGroupAssoc".equals(valueObj.getEntityName())) { - // assign the ship group - if (orderItemSeqId.equals(valueObj.getString("orderItemSeqId"))) { - Debug.log("Explode OrderItemShipGroupAssoc [" + valueObj.toString() + "]", module); - for (int a = 0; assocOrderItems.size() > a; a++) { - GenericValue assocOrderItem = (GenericValue) assocOrderItems.get(a); - String assocOrderItemSeqId = assocOrderItem.getString("orderItemSeqId"); - GenericValue newValueObj = GenericValue.create(valueObj); - newValueObj.put("orderItemSeqId", assocOrderItemSeqId); - newValueObj.put("quantity", assocOrderItem.getDouble("quantity")); - newOrderItemShipGroupInfo.add(newValueObj); - Debug.log("Create new OrderItemShipGroupAssoc [" + newValueObj.toString() + "]", module); - }//for - }//if - } else if ("OrderAdjustment".equals(valueObj.getEntityName())) { - // orderItemShipGroupInfo might also contain an order adjustment for tax adjustments to this ship group. In that case, - // pro-rate it as well. - // TODO: it would be nice to re-factor this with the pro-rating code up above into one common code block. - if (orderItemSeqId.equals(valueObj.getString("orderItemSeqId"))) { - Debug.log("Explode OrderAdjustment [" + valueObj.toString() + "] ", module); - for (int a = 0; assocOrderItems.size() > a; a++) { - GenericValue assocOrderItem = (GenericValue) assocOrderItems.get(a); - String assocOrderItemSeqId = assocOrderItem.getString("orderItemSeqId"); - - Double productToQuantity = assocOrderItem.getDouble("cancelQuantity"); - Double amount = valueObj.getDouble("amount"); - - Double percentage = new Double(productToQuantity.doubleValue() / sumAssocQty); - amount = new Double(amount.doubleValue() * percentage.doubleValue()); - GenericValue newValueObj = GenericValue.create(valueObj); - Double itemQuantity = assocOrderItem.getDouble("quantity"); - newValueObj.put("sourcePercentage", new Double(amount.doubleValue() / itemQuantity.doubleValue())); - newValueObj.put("orderItemSeqId", assocOrderItemSeqId); - newValueObj.put("amount", amount); - newOrderItemShipGroupInfo.add(newValueObj); - Debug.log("Create new Order Adjustment [" + newValueObj.toString() + "]", module); - }//for - }//if - }//if - }//while - }//if - - for (int a = 0; assocOrderItems.size() > a; a++) { - GenericValue assocOrderItem = (GenericValue) assocOrderItems.get(a); - assocOrderItem.remove("cancelQuantity"); - newOrderItems.add(assocOrderItem); - }//for - - // Deal with price rules: get all price rules for this line item by filtering the input price infos for this order item's seq id - List andCondList = UtilMisc.toList(new EntityExpr("orderItemSeqId", EntityOperator.EQUALS, orderItem.getString("orderItemSeqId"))); - List lineItemPriceInfos = EntityUtil.filterByAnd(orderItemPriceInfo, andCondList); - if ((lineItemPriceInfos != null) && (lineItemPriceInfos.size() > 0)) { - - // loop through the exploded items - Iterator expItemIter = assocOrderItems.iterator(); - while (expItemIter.hasNext()) { - GenericValue expItem = (GenericValue) expItemIter.next(); - - // apply price rules - List newOrderItemPriceInfos = new LinkedList(); - Iterator oipii = lineItemPriceInfos.iterator(); - while (oipii.hasNext()) { - GenericValue oipi = (GenericValue) oipii.next(); - GenericValue newoipi = (GenericValue) oipi.clone(); - newoipi.set("orderItemSeqId", expItem.getString("orderItemSeqId")); - newOrderItemPriceInfos.add(newoipi); - Debug.logInfo("Applying price rule " + oipi.getString("productPriceRuleId") + " to order item seq Id " + expItem.getString("orderItemSeqId"), module); - } - // add the new order item price infos - orderItemPriceInfo.addAll(newOrderItemPriceInfos); - } - // finally, remove the price infos for the marketing package - orderItemPriceInfo.removeAll(lineItemPriceInfos); - } - } else { - //deal with the orderItem which cannot be explode - just carry them with their adjustments over in the same ship group - newOrderItems.add(orderItem); - //order adjustment - if (orderAdjustments != null && orderAdjustments.size() > 0) { - for (int a = 0; orderAdjustments.size() > a; a++) { - GenericValue orderAdjustment = (GenericValue) orderAdjustments.get(a); - if (orderItemSeqId.equals(orderAdjustment.getString("orderItemSeqId"))) { - newOrderAdjustments.add(orderAdjustment); - }//if - }//for - }//if - //order item ship group - if (orderItemShipGroupInfo != null && orderItemShipGroupInfo.size() > 0) { - Iterator osiInfos = orderItemShipGroupInfo.iterator(); - while (osiInfos.hasNext()) { - GenericValue valueObj = (GenericValue) osiInfos.next(); - if ("OrderAdjustment".equals(valueObj.getEntityName()) || "OrderItemShipGroupAssoc".equals(valueObj.getEntityName())) { - if (orderItemSeqId.equals(valueObj.getString("orderItemSeqId"))) { - newOrderItemShipGroupInfo.add(valueObj); - }//if - }//if - }//while - }//if - } // if - } catch (Exception e) { - Debug.logWarning(e, "There was an error in the [explodeMarketingPkgAutoItem]: " + e.getMessage(), module); - throw e; - }// try - }// while - - orderItems.clear(); - orderItems.addAll(newOrderItems); - orderAdjustments.clear(); - orderAdjustments.addAll(newOrderAdjustments); - orderItemShipGroupInfo.clear(); - orderItemShipGroupInfo.addAll(newOrderItemShipGroupInfo); - }// explodeMarketingPkgAutoItem public static Map massChangeApproved(DispatchContext dctx, Map context) { LocalDispatcher dispatcher = dctx.getDispatcher(); Modified: incubator/ofbiz/trunk/applications/product/data/ProductTypeData.xml URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/product/data/ProductTypeData.xml?rev=424117&r1=424116&r2=424117&view=diff ============================================================================== --- incubator/ofbiz/trunk/applications/product/data/ProductTypeData.xml (original) +++ incubator/ofbiz/trunk/applications/product/data/ProductTypeData.xml Thu Jul 20 16:39:46 2006 @@ -148,8 +148,6 @@ <ProductAssocType description="Complementary or Cross-Sell" hasTable="N" parentTypeId="" productAssocTypeId="PRODUCT_COMPLEMENT"/> <ProductAssocType description="Incompatable" hasTable="N" parentTypeId="" productAssocTypeId="PRODUCT_INCOMPATABLE"/> <ProductAssocType description="New Version, Replacement" hasTable="N" parentTypeId="" productAssocTypeId="PRODUCT_OBSOLESCENCE"/> - <ProductAssocType description="Marketing Package Component ** DEPRECATED **" hasTable="N" parentTypeId="" productAssocTypeId="MARKETING_PACKAGE"/> - <ProductAssocType description="Marketing Package Auto Explode Component ** DEPRECATED **" hasTable="N" parentTypeId="" productAssocTypeId="MARKETING_PKG_AUTO"/> <ProductAssocType description="Actual Product Component" hasTable="N" parentTypeId="" productAssocTypeId="PRODUCT_COMPONENT"/> <ProductAssocType description="Equivalent or Substitute" hasTable="N" parentTypeId="" productAssocTypeId="PRODUCT_SUBSTITUTE"/> <ProductAssocType description="Product Variant" hasTable="N" parentTypeId="" productAssocTypeId="PRODUCT_VARIANT"/> |
Free forum by Nabble | Edit this page |