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

📄 shoppingcartservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * $Id: ShoppingCartServices.java 7094 2006-03-27 21:35:24Z jaz $ * * Copyright (c) 2004 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */package org.ofbiz.order.shoppingcart;import java.util.Iterator;import java.util.List;import java.util.Locale;import java.util.Map;import java.util.HashMap;import java.util.LinkedList;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.GeneralException;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.condition.EntityCondition;import org.ofbiz.entity.condition.EntityConditionList;import org.ofbiz.entity.condition.EntityExpr;import org.ofbiz.entity.condition.EntityOperator;import org.ofbiz.order.order.OrderReadHelper;import org.ofbiz.service.DispatchContext;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ServiceUtil;/** * Shopping Cart Services * * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @version    $Rev: 7094 $ * @since      3.3 */public class ShoppingCartServices {    public static final String module = ShoppingCartServices.class.getName();    public static final String resource = "OrderUiLabels";    public static final String resource_error = "OrderErrorUiLabels";    public static Map assignItemShipGroup(DispatchContext dctx, Map context) {        ShoppingCart cart = (ShoppingCart) context.get("shoppingCart");        Integer fromGroupIndex = (Integer) context.get("fromGroupIndex");        Integer toGroupIndex = (Integer) context.get("toGroupIndex");        Integer itemIndex = (Integer) context.get("itemIndex");        Double quantity = (Double) context.get("quantity");        Locale locale = (Locale) context.get("locale");        Debug.log("From Group - " + fromGroupIndex + " To Group - " + toGroupIndex + "Item - " + itemIndex + "(" + quantity + ")", module);        if (fromGroupIndex.equals(toGroupIndex)) {            // nothing to do            return ServiceUtil.returnSuccess();        }        cart.positionItemToGroup(itemIndex.intValue(), quantity.doubleValue(),                fromGroupIndex.intValue(), toGroupIndex.intValue());        Debug.log("Called cart.positionItemToGroup()", module);        return ServiceUtil.returnSuccess();    }    public static Map setShippingOptions(DispatchContext dctx, Map context) {        ShoppingCart cart = (ShoppingCart) context.get("shoppingCart");        Integer groupIndex = (Integer) context.get("groupIndex");        String shippingContactMechId = (String) context.get("shippingContactMechId");        String shipmentMethodString = (String) context.get("shipmentMethodString");        String shippingInstructions = (String) context.get("shippingInstructions");        String giftMessage = (String) context.get("giftMessage");        Boolean maySplit = (Boolean) context.get("maySplit");        Boolean isGift = (Boolean) context.get("isGift");        Locale locale = (Locale) context.get("locale");        ShoppingCart.CartShipInfo csi = cart.getShipInfo(groupIndex.intValue());        if (csi != null) {            int idx = groupIndex.intValue();            if (UtilValidate.isNotEmpty(shipmentMethodString)) {                int delimiterPos = shipmentMethodString.indexOf('@');                String shipmentMethodTypeId = null;                String carrierPartyId = null;                if (delimiterPos > 0) {                    shipmentMethodTypeId = shipmentMethodString.substring(0, delimiterPos);                    carrierPartyId = shipmentMethodString.substring(delimiterPos + 1);                 }                cart.setShipmentMethodTypeId(idx, shipmentMethodTypeId);                cart.setCarrierPartyId(idx, carrierPartyId);            }            cart.setShippingInstructions(idx, shippingInstructions);            cart.setShippingContactMechId(idx, shippingContactMechId);            cart.setGiftMessage(idx, giftMessage);            if (maySplit != null) {                cart.setMaySplit(idx, maySplit);            }            if (isGift != null) {                cart.setIsGift(idx, isGift);            }        } else {        	return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderCartShipGroupNotFound", UtilMisc.toMap("groupIndex",groupIndex), locale));        }        return ServiceUtil.returnSuccess();    }    public static Map setPaymentOptions(DispatchContext dctx, Map context) {    	Locale locale = (Locale) context.get("locale");    	return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderServiceNotYetImplemented",locale));    }    public static Map setOtherOptions(DispatchContext dctx, Map context) {        ShoppingCart cart = (ShoppingCart) context.get("shoppingCart");        String orderAdditionalEmails = (String) context.get("orderAdditionalEmails");        String correspondingPoId = (String) context.get("correspondingPoId");        Locale locale = (Locale) context.get("locale");        cart.setOrderAdditionalEmails(orderAdditionalEmails);        if (UtilValidate.isNotEmpty(correspondingPoId)) {            cart.setPoNumber(correspondingPoId);        } else {            cart.setPoNumber(null);        }        return ServiceUtil.returnSuccess();    }    public static Map loadCartFromOrder(DispatchContext dctx, Map context) {        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericDelegator delegator = dctx.getDelegator();        GenericValue userLogin = (GenericValue) context.get("userLogin");        String orderId = (String) context.get("orderId");        Locale locale = (Locale) context.get("locale");        // get the order header        GenericValue orderHeader = null;        try {            orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));        } catch (GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError(e.getMessage());        }        // initial require cart info        OrderReadHelper orh = new OrderReadHelper(orderHeader);        String productStoreId = orh.getProductStoreId();        String orderTypeId = orh.getOrderTypeId();        String currency = orh.getCurrency();        String website = orh.getWebSiteId();        // create the cart        ShoppingCart cart = new ShoppingCart(delegator, productStoreId, website, locale, currency);        cart.setOrderType(orderTypeId);        try {            cart.setUserLogin(userLogin, dispatcher);        } catch (CartItemModifyException e) {            Debug.logError(e, module);            return ServiceUtil.returnError(e.getMessage());        }        // set the role information        GenericValue placingParty = orh.getPlacingParty();        if (placingParty != null) {            cart.setPlacingCustomerPartyId(placingParty.getString("partyId"));        }        GenericValue billFromParty = orh.getBillFromParty();        if (billFromParty != null) {            cart.setBillFromVendorPartyId(billFromParty.getString("partyId"));        }                    GenericValue billToParty = orh.getBillToParty();        if (billToParty != null) {            cart.setBillToCustomerPartyId(billToParty.getString("partyId"));        }        GenericValue shipToParty = orh.getShipToParty();        if (shipToParty != null) {            cart.setShipToCustomerPartyId(shipToParty.getString("partyId"));        }        GenericValue endUserParty = orh.getEndUserParty();        if (endUserParty != null) {            cart.setEndUserCustomerPartyId(endUserParty.getString("partyId"));            cart.setOrderPartyId(endUserParty.getString("partyId"));        }        // load the payment infos        List orderPaymentPrefs = null;        try {            List exprs = UtilMisc.toList(new EntityExpr("orderId", EntityOperator.EQUALS, orderId));            exprs.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "PAYMENT_RECEIVED"));            exprs.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "PAYMENT_CANCELLED"));            exprs.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "PAYMENT_DECLINED"));            exprs.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "PAYMENT_SETTLED"));            EntityCondition cond = new EntityConditionList(exprs, EntityOperator.AND);            orderPaymentPrefs = delegator.findByCondition("OrderPaymentPreference", cond, null, null);        } catch (GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError(e.getMessage());        }        if (orderPaymentPrefs != null && orderPaymentPrefs.size() > 0) {            Iterator oppi = orderPaymentPrefs.iterator();            while (oppi.hasNext()) {                GenericValue opp = (GenericValue) oppi.next();                String paymentId = opp.getString("paymentMethodId");                if(paymentId==null)                    paymentId = opp.getString("paymentMethodTypeId");                Double maxAmount = opp.getDouble("maxAmount");                String overflow = opp.getString("overflowFlag");                if ((overflow == null || !"Y".equals(overflow)) && oppi.hasNext()) {                    cart.addPaymentAmount(paymentId, maxAmount);                    Debug.log("Added Payment: " + paymentId + " / " + maxAmount, module);                } else {

⌨️ 快捷键说明

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