⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shippingevents.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

        if (Debug.verboseOn()) Debug.logVerbose("[ShippingEvents.getShipEstimate] Estimates left after GEO filter: " + estimateList.size(), module);

        if (estimateList.size() < 1) {
            Debug.logInfo("[ShippingEvents.getShipEstimate] No shipping estimate found.", module);
            return ServiceUtil.returnSuccess(standardMessage);
        }

        // Calculate priority based on available data.
        double PRIORITY_PARTY = 9;
        double PRIORITY_ROLE = 8;
        double PRIORITY_GEO = 4;
        double PRIORITY_WEIGHT = 1;
        double PRIORITY_QTY = 1;
        double PRIORITY_PRICE = 1;

        int estimateIndex = 0;

        if (estimateList.size() > 1) {
            TreeMap estimatePriority = new TreeMap();
            //int estimatePriority[] = new int[estimateList.size()];

            for (int x = 0; x < estimateList.size(); x++) {
                GenericValue currentEstimate = (GenericValue) estimateList.get(x);

                int prioritySum = 0;
                if (UtilValidate.isNotEmpty(currentEstimate.getString("partyId")))
                    prioritySum += PRIORITY_PARTY;
                if (UtilValidate.isNotEmpty(currentEstimate.getString("roleTypeId")))
                    prioritySum += PRIORITY_ROLE;
                if (UtilValidate.isNotEmpty(currentEstimate.getString("geoIdTo")))
                    prioritySum += PRIORITY_GEO;
                if (UtilValidate.isNotEmpty(currentEstimate.getString("weightBreakId")))
                    prioritySum += PRIORITY_WEIGHT;
                if (UtilValidate.isNotEmpty(currentEstimate.getString("quantityBreakId")))
                    prioritySum += PRIORITY_QTY;
                if (UtilValidate.isNotEmpty(currentEstimate.getString("priceBreakId")))
                    prioritySum += PRIORITY_PRICE;

                // there will be only one of each priority; latest will replace
                estimatePriority.put(new Integer(prioritySum), currentEstimate);
            }

            // locate the highest priority estimate; or the latest entered
            Object[] estimateArray = estimatePriority.values().toArray();
            estimateIndex = estimateList.indexOf(estimateArray[estimateArray.length - 1]);
        }

        // Grab the estimate and work with it.
        GenericValue estimate = (GenericValue) estimateList.get(estimateIndex);

        //Debug.log("[ShippingEvents.getShipEstimate] Working with estimate [" + estimateIndex + "]: " + estimate, module);

        // flat fees
        double orderFlat = 0.00;
        if (estimate.getDouble("orderFlatPrice") != null)
            orderFlat = estimate.getDouble("orderFlatPrice").doubleValue();

        double orderItemFlat = 0.00;
        if (estimate.getDouble("orderItemFlatPrice") != null)
            orderItemFlat = estimate.getDouble("orderItemFlatPrice").doubleValue();

        double orderPercent = 0.00;
        if (estimate.getDouble("orderPricePercent") != null)
            orderPercent = estimate.getDouble("orderPricePercent").doubleValue();

        double itemFlatAmount = shippableQuantity * orderItemFlat;
        double orderPercentage = shippableTotal * (orderPercent / 100);

        // flat total
        double flatTotal = orderFlat + itemFlatAmount + orderPercentage;

        // spans
        double weightUnit = 0.00;
        if (estimate.getDouble("weightUnitPrice") != null)
            weightUnit = estimate.getDouble("weightUnitPrice").doubleValue();

        double qtyUnit = 0.00;
        if (estimate.getDouble("quantityUnitPrice") != null)
            qtyUnit = estimate.getDouble("quantityUnitPrice").doubleValue();

        double priceUnit = 0.00;
        if (estimate.getDouble("priceUnitPrice") != null)
            priceUnit = estimate.getDouble("priceUnitPrice").doubleValue();

        double weightAmount = shippableWeight * weightUnit;
        double quantityAmount = shippableQuantity * qtyUnit;
        double priceAmount = shippableTotal * priceUnit;

        // span total
        double spanTotal = weightAmount + quantityAmount + priceAmount;

        // feature surcharges
        double featureSurcharge = 0.00;
        String featureGroupId = estimate.getString("productFeatureGroupId");
        Double featurePercent = estimate.getDouble("featurePercent");
        Double featurePrice = estimate.getDouble("featurePrice");
        if (featurePercent == null) {
            featurePercent = new Double(0);
        }
        if (featurePrice == null) {
            featurePrice = new Double(0.00);
        }

        if (featureGroupId != null && featureGroupId.length() > 0 && featureMap != null ) {
            Iterator fii = featureMap.keySet().iterator();
            while (fii.hasNext()) {
                String featureId = (String) fii.next();
                Double quantity = (Double) featureMap.get(featureId);
                GenericValue appl = null;
                Map fields = UtilMisc.toMap("productFeatureGroupId", featureGroupId, "productFeatureId", featureId);
                try {
                    List appls = delegator.findByAndCache("ProductFeatureGroupAppl", fields);
                    appls = EntityUtil.filterByDate(appls);
                    appl = EntityUtil.getFirst(appls);
                } catch (GenericEntityException e) {
                    Debug.logError(e, "Unable to lookup feature/group" + fields, module);
                }
                if (appl != null) {
                    featureSurcharge += (shippableTotal * (featurePercent.doubleValue() / 100) * quantity.doubleValue());
                    featureSurcharge += featurePrice.doubleValue() * quantity.doubleValue();
                }
            }
        }

        // size surcharges
        double sizeSurcharge = 0.00;
        Double sizeUnit = estimate.getDouble("oversizeUnit");
        Double sizePrice = estimate.getDouble("oversizePrice");
        if (sizeUnit != null && sizeUnit.doubleValue() > 0) {
            if (itemSizes != null) {
                Iterator isi = itemSizes.iterator();
                while (isi.hasNext()) {
                    Double size = (Double) isi.next();
                    if (size != null && size.doubleValue() >= sizeUnit.doubleValue()) {
                        sizeSurcharge += sizePrice.doubleValue();
                    }
                }
            }
        }

        // surcharges total
        double surchargeTotal = featureSurcharge + sizeSurcharge;

        // shipping total
        double shippingTotal = spanTotal + flatTotal + surchargeTotal;

        if (Debug.verboseOn()) Debug.logVerbose("[ShippingEvents.getShipEstimate] Setting shipping amount : " + shippingTotal, module);

        Map responseResult = ServiceUtil.returnSuccess();
        responseResult.put("shippingTotal", new Double(shippingTotal));
        return responseResult;
    }

    /*
     * Reserved for future use.
     *
     private static double getUPSRate(ShoppingCart cart, String fromZip, String upsMethod) {
     HttpClient req = new HttpClient();
     HashMap arguments = new HashMap();
     double totalWeight = 0.00000;
     double upsRate = 0.00;

     HashMap services = new HashMap();
     services.put("1DA","Next Day Air");
     services.put("1DM","Next Day Air Early");
     services.put("1DP","Next Day Air Saver");
     services.put("1DAPI","Next Day Air Intra (Puerto Rico)");
     services.put("2DA","2nd Day Air");
     services.put("2DM","2nd Day Air A.M.");
     services.put("3DS","3rd Day");
     services.put("GND","Ground Service");
     services.put("STD","Canada Standard");
     services.put("XPR","Worldwide Express");
     services.put("XDM","Worldwide Express Plus");
     services.put("XPD","Worldwide Expedited");

     if ( !services.containsKey(upsMethod) )
     return 0.00;

     // Get the total weight from the cart.
     Iterator cartItemIterator = cart.iterator();
     while ( cartItemIterator.hasNext() ) {
     ShoppingCartItem item = (ShoppingCartItem) cartItemIterator.next();
     totalWeight += (item.getWeight() * item.getQuantity());
     }
     String weightString = new Double(totalWeight).toString();
     if (Debug.infoOn()) Debug.logInfo("[ShippingEvents.getUPSRate] Total Weight: " + weightString, module);

     // Set up the UPS arguments.
     arguments.put("AppVersion","1.2");
     arguments.put("ResponseType","application/x-ups-rss");
     arguments.put("AcceptUPSLicenseAgreement","yes");

     arguments.put("RateChart","Regular Daily Pickup");              // ?
     arguments.put("PackagingType","00");                                  // Using own container
     arguments.put("ResidentialInd","1");                                     // Assume residential

     arguments.put("ShipperPostalCode",fromZip);                      // Ship From ZipCode
     arguments.put("ConsigneeCountry","US");                            // 2 char country ISO
     arguments.put("ConsigneePostalCode","27703");                 // Ship TO ZipCode
     arguments.put("PackageActualWeight",weightString);          // Total shipment weight

     arguments.put("ActionCode","3");                                         // Specify the shipping type. (4) to get all
     arguments.put("ServiceLevelCode",upsMethod);                   // User's shipping choice (or 1DA for ActionCode 4)

     String upsResponse = null;
     try {
     req.setUrl(UPS_RATES_URL);
     req.setLineFeed(false);
     req.setParameters(arguments);
     upsResponse = req.get();
     }
     catch ( HttpClientException e ) {
     Debug.logError("[ShippingEvents.getUPSRate] Problems getting UPS Rate Infomation.", module);
     return -1;
     }

     if ( upsResponse.indexOf("application/x-ups-error") != -1 ) {
     // get the error message
     }
     else if ( upsResponse.indexOf("application/x-ups-rss") != -1 ) {
     // get the content
     upsResponse = upsResponse.substring(upsResponse.indexOf("UPSOnLine"));
     upsResponse = upsResponse.substring(0,upsResponse.indexOf("--UPSBOUNDARY--") -1 );
     ArrayList respList = new ArrayList();
     while ( upsResponse.indexOf("%") != -1 ) {
     respList.add(upsResponse.substring(0,upsResponse.indexOf("%")));
     upsResponse = upsResponse.substring(upsResponse.indexOf("%") + 1);
     if ( upsResponse.indexOf("%") == -1 )
     respList.add(upsResponse);
     }

     // Debug:
     Iterator i = respList.iterator();
     while ( i.hasNext() ) {
     String value = (String) i.next();
     if (Debug.infoOn()) Debug.logInfo("[ShippingEvents.getUPSRate] Resp List: " + value, module);
     }

     // Shipping method is index 5
     // Shipping rate is index 12
     if ( !respList.get(5).equals(upsMethod) )
     Debug.logInfo("[ShippingEvents.getUPSRate] Shipping method does not match.", module);
     try {
     upsRate = Double.parseDouble((String)respList.get(12));
     }
     catch ( NumberFormatException nfe ) {
     Debug.logError("[ShippingEvents.getUPSRate] Problems parsing rate value.", module);
     }
     }

     return upsRate;
     }
     */

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -