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

📄 shoppingcart.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * $Id: ShoppingCart.java 7271 2006-04-11 00:55:00Z sichen $ * *  Copyright (c) 2001-2005 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.io.Serializable;import java.sql.Timestamp;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.Comparator;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Locale;import java.util.Map;import java.util.Set;import org.apache.commons.collections.map.LinkedMap;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.GeneralException;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.base.util.UtilFormatOut;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericPK;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.party.contact.ContactHelper;import org.ofbiz.order.order.OrderReadHelper;import org.ofbiz.order.finaccount.FinAccountHelper;import org.ofbiz.order.shoppingcart.product.ProductPromoWorker;import org.ofbiz.order.shoppingcart.shipping.ShippingEstimateWrapper;import org.ofbiz.order.shoppinglist.ShoppingListEvents;import org.ofbiz.product.config.ProductConfigWrapper;import org.ofbiz.product.store.ProductStoreWorker;import org.ofbiz.service.LocalDispatcher;/** * Shopping Cart Object * * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @version    $Rev: 7271 $ * @since      2.0 */public class ShoppingCart implements Serializable {    public static final String module = ShoppingCart.class.getName();    public static final String resource_error = "OrderErrorUiLabels";    private String orderType = "SALES_ORDER"; // default orderType    private String channel = "UNKNWN_SALES_CHANNEL"; // default channel enum    private String poNumber = null;    private String orderId = null;    private String firstAttemptOrderId = null;    private String externalId = null;    private String internalCode = null;    private String billingAccountId = null;    private double billingAccountAmt = 0.00;    private String agreementId = null;    private String quoteId = null;    private long nextItemSeq = 1;    private String defaultItemDeliveryDate = null;    private String defaultItemComment = null;    private String orderAdditionalEmails = null;    private boolean viewCartOnAdd = false;    private boolean readOnlyCart = false;    private Timestamp lastListRestore = null;    private String autoSaveListId = null;    /** Holds value of order adjustments. */    private List adjustments = new LinkedList();    // OrderTerms    private boolean orderTermSet = false;    private List orderTerms = new LinkedList();    private List cartLines = new LinkedList();    private List paymentInfo = new LinkedList();    private List shipInfo = new LinkedList();    private Map contactMechIdsMap = new HashMap();    private Map orderAttributes = new HashMap();    private Map attributes = new HashMap(); // user defined attributes    /** contains a list of partyId for each roleTypeId (key) */    private Map additionalPartyRole = new HashMap();    /** these are defaults for all ship groups */    private Timestamp defaultShipAfterDate = null;    private Timestamp defaultShipBeforeDate = null;        public static class ProductPromoUseInfo implements Serializable {        public String productPromoId = null;        public String productPromoCodeId = null;        public double totalDiscountAmount = 0;        public double quantityLeftInActions = 0;        public ProductPromoUseInfo(String productPromoId, String productPromoCodeId, double totalDiscountAmount, double quantityLeftInActions) {            this.productPromoId = productPromoId;            this.productPromoCodeId = productPromoCodeId;            this.totalDiscountAmount = totalDiscountAmount;            this.quantityLeftInActions = quantityLeftInActions;        }        public String getProductPromoId() { return this.productPromoId; }        public String getProductPromoCodeId() { return this.productPromoCodeId; }        public double getTotalDiscountAmount() { return this.totalDiscountAmount; }        public double getQuantityLeftInActions() { return this.quantityLeftInActions; }    }    public static class CartShipInfo implements Serializable {        public LinkedMap shipItemInfo = new LinkedMap();        public List shipTaxAdj = new LinkedList();        public String contactMechId = null;        public String shipmentMethodTypeId = null;        public String carrierRoleTypeId = null;        public String carrierPartyId = null;        public String giftMessage = null;        public String shippingInstructions = null;        public String maySplit = "N";        public String isGift = "N";        public double shipEstimate = 0.00;        public Timestamp shipBeforeDate = null;        public Timestamp shipAfterDate = null;        public List makeItemShipGroupAndAssoc(GenericDelegator delegator, ShoppingCart cart, long groupIndex) {            String shipGroupSeqId = UtilFormatOut.formatPaddedNumber(groupIndex, 5);            List values = new LinkedList();                        // create order contact mech for shipping address            if (contactMechId != null) {                GenericValue orderCm = delegator.makeValue("OrderContactMech", null);                orderCm.set("contactMechPurposeTypeId", "SHIPPING_LOCATION");                orderCm.set("contactMechId", contactMechId);                values.add(orderCm);            }            // create the ship group            GenericValue shipGroup = delegator.makeValue("OrderItemShipGroup", null);            shipGroup.set("shipmentMethodTypeId", shipmentMethodTypeId);            shipGroup.set("carrierRoleTypeId", carrierRoleTypeId);            shipGroup.set("carrierPartyId", carrierPartyId);            shipGroup.set("shippingInstructions", shippingInstructions);            shipGroup.set("giftMessage", giftMessage);            shipGroup.set("contactMechId", contactMechId);            shipGroup.set("maySplit", maySplit);            shipGroup.set("isGift", isGift);            shipGroup.set("shipGroupSeqId", shipGroupSeqId);                        // use the cart's default ship before and after dates here            if ((shipBeforeDate == null) && (cart.getDefaultShipBeforeDate() != null)) {                shipGroup.set("shipByDate", cart.getDefaultShipBeforeDate());            } else {                shipGroup.set("shipByDate", shipBeforeDate);            }            if ((shipAfterDate == null) && (cart.getDefaultShipAfterDate() != null)) {                shipGroup.set("shipAfterDate", cart.getDefaultShipAfterDate());            } else {                shipGroup.set("shipAfterDate", shipAfterDate);            }                        values.add(shipGroup);            // create the shipping estimate adjustments            if (shipEstimate != 0) {                GenericValue shipAdj = delegator.makeValue("OrderAdjustment", null);                shipAdj.set("orderAdjustmentTypeId", "SHIPPING_CHARGES");                shipAdj.set("amount", new Double(shipEstimate));                shipAdj.set("shipGroupSeqId", shipGroupSeqId);                values.add(shipAdj);            }            // create the top level tax adjustments            Iterator ti = shipTaxAdj.iterator();            while (ti.hasNext()) {                GenericValue taxAdj = (GenericValue) ti.next();                taxAdj.set("shipGroupSeqId", shipGroupSeqId);                values.add(taxAdj);            }            // create the ship group item associations            Iterator i = shipItemInfo.keySet().iterator();            while (i.hasNext()) {                ShoppingCartItem item = (ShoppingCartItem) i.next();                CartShipItemInfo itemInfo = (CartShipItemInfo) shipItemInfo.get(item);                GenericValue assoc = delegator.makeValue("OrderItemShipGroupAssoc", null);                assoc.set("orderItemSeqId", item.getOrderItemSeqId());                assoc.set("shipGroupSeqId", shipGroupSeqId);                assoc.set("quantity", new Double(itemInfo.quantity));                values.add(assoc);                // create the item tax adjustment                Iterator iti = itemInfo.itemTaxAdj.iterator();                while (iti.hasNext()) {                    GenericValue taxAdj = (GenericValue) iti.next();                    taxAdj.set("orderItemSeqId", item.getOrderItemSeqId());                    taxAdj.set("shipGroupSeqId", shipGroupSeqId);                    values.add(taxAdj);                }            }            return values;        }        public CartShipItemInfo setItemInfo(ShoppingCartItem item, double quantity, List taxAdj) {            CartShipItemInfo itemInfo = (CartShipItemInfo) shipItemInfo.get(item);            if (itemInfo == null) {                itemInfo = new CartShipItemInfo();                itemInfo.item = item;                shipItemInfo.put(item, itemInfo);            }            itemInfo.quantity = quantity;            itemInfo.itemTaxAdj.clear();            if (taxAdj == null) {                taxAdj = new LinkedList();            }            itemInfo.itemTaxAdj.addAll(taxAdj);            return itemInfo;        }        public CartShipItemInfo setItemInfo(ShoppingCartItem item, List taxAdj) {            CartShipItemInfo itemInfo = (CartShipItemInfo) shipItemInfo.get(item);            if (itemInfo == null) {                itemInfo = new CartShipItemInfo();                itemInfo.item = item;                shipItemInfo.put(item, itemInfo);            }            itemInfo.itemTaxAdj.clear();            if (taxAdj == null) {                taxAdj = new LinkedList();            }            itemInfo.itemTaxAdj.addAll(taxAdj);            return itemInfo;        }        public CartShipItemInfo setItemInfo(ShoppingCartItem item, double quantity) {            CartShipItemInfo itemInfo = (CartShipItemInfo) shipItemInfo.get(item);            if (itemInfo == null) {                itemInfo = new CartShipItemInfo();                itemInfo.item = item;                shipItemInfo.put(item, itemInfo);            }            itemInfo.quantity = quantity;            return itemInfo;        }        public CartShipItemInfo getShipItemInfo(ShoppingCartItem item) {            return (CartShipItemInfo) shipItemInfo.get(item);        }        public Set getShipItems() {            return shipItemInfo.keySet();        }        /**         * Reset the ship group's shipBeforeDate if it is after the parameter          * @param newShipBeforeDate         */        public void resetShipBeforeDateIfAfter(Timestamp newShipBeforeDate) {        	if (newShipBeforeDate != null) {                if ((this.shipBeforeDate == null) || (!this.shipBeforeDate.before(newShipBeforeDate))) {                    this.shipBeforeDate = newShipBeforeDate;                }            }        }                /**         * Reset the ship group's shipAfterDate if it is before the parameter          * @param newShipBeforeDate         */        public void resetShipAfterDateIfBefore(Timestamp newShipAfterDate) {            if (newShipAfterDate != null) {                if ((this.shipAfterDate == null) || (!this.shipAfterDate.after(newShipAfterDate))) {                    this.shipAfterDate = newShipAfterDate;                }            }        }                public double getTotalTax(ShoppingCart cart) {            double taxTotal = 0.00;            for (int i = 0; i < shipTaxAdj.size(); i++) {                GenericValue v = (GenericValue) shipTaxAdj.get(i);                taxTotal += OrderReadHelper.calcOrderAdjustment(v, cart.getSubTotal());            }            Iterator iter = shipItemInfo.values().iterator();            while (iter.hasNext()) {                CartShipItemInfo info = (CartShipItemInfo) iter.next();                taxTotal += info.getItemTax(cart);            }            return taxTotal;        }

⌨️ 快捷键说明

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