📄 shoppingcart.java
字号:
public static class CartShipItemInfo implements Serializable { public List itemTaxAdj = new LinkedList(); public ShoppingCartItem item = null; public double quantity = 0; public double getItemTax(ShoppingCart cart) { double itemTax = 0.00; for (int i = 0; i < itemTaxAdj.size(); i++) { GenericValue v = (GenericValue) itemTaxAdj.get(i); itemTax += OrderReadHelper.calcItemAdjustment(v, new Double(quantity), new Double(item.getBasePrice())); } return itemTax; } public double getItemQuantity() { return this.quantity; } } } public static class CartPaymentInfo implements Serializable, Comparable { public String paymentMethodTypeId = null; public String paymentMethodId = null; public String securityCode = null; public String postalCode = null; public String[] refNum = new String[2]; public Double amount = null; public boolean singleUse = false; public boolean isPresent = false; public boolean overflow = false; public GenericValue getValueObject(GenericDelegator delegator) { String entityName = null; Map lookupFields = null; if (paymentMethodId != null) { lookupFields = UtilMisc.toMap("paymentMethodId", paymentMethodId); entityName = "PaymentMethod"; } else if (paymentMethodTypeId != null) { lookupFields = UtilMisc.toMap("paymentMethodTypeId", paymentMethodTypeId); entityName = "PaymentMethodType"; } else { throw new IllegalArgumentException("Could not create value object because paymentMethodId and paymentMethodTypeId are null"); } try { return delegator.findByPrimaryKeyCache(entityName, lookupFields); } catch (GenericEntityException e) { Debug.logError(e, module); } return null; } public GenericValue getBillingAddress(GenericDelegator delegator) { GenericValue valueObj = this.getValueObject(delegator); GenericValue postalAddress = null; if ("PaymentMethod".equals(valueObj.getEntityName())) { String paymentMethodTypeId = valueObj.getString("paymentMethodTypeId"); String paymentMethodId = valueObj.getString("paymentMethodId"); Map lookupFields = UtilMisc.toMap("paymentMethodId", paymentMethodId); // billing account, credit card, gift card, eft account all have postal address try { GenericValue pmObj = null; if ("CREDIT_CARD".equals(paymentMethodTypeId)) { pmObj = delegator.findByPrimaryKey("CreditCard", lookupFields); } else if ("GIFT_CARD".equals(paymentMethodTypeId)) { pmObj = delegator.findByPrimaryKey("GiftCard", lookupFields); } else if ("EFT_ACCOUNT".equals(paymentMethodTypeId)) { pmObj = delegator.findByPrimaryKey("EftAccount", lookupFields); } else if ("EXT_BILLACT".equals(paymentMethodTypeId)) { pmObj = delegator.findByPrimaryKey("BillingAccount", lookupFields); } if (pmObj != null) { postalAddress = pmObj.getRelatedOne("PostalAddress"); } else { Debug.logInfo("No PaymentMethod Object Found - " + paymentMethodId, module); } } catch (GenericEntityException e) { Debug.logError(e, module); } } return postalAddress; } public List makeOrderPaymentInfos(GenericDelegator delegator) { GenericValue valueObj = this.getValueObject(delegator); List values = new LinkedList(); if (valueObj != null) { // first create a BILLING_LOCATION for the payment method address if there is one if ("PaymentMethod".equals(valueObj.getEntityName())) { String paymentMethodTypeId = valueObj.getString("paymentMethodTypeId"); String paymentMethodId = valueObj.getString("paymentMethodId"); Map lookupFields = UtilMisc.toMap("paymentMethodId", paymentMethodId); String billingAddressId = null; GenericValue billingAddress = this.getBillingAddress(delegator); if (billingAddress != null) { billingAddressId = billingAddress.getString("contactMechId"); } if (UtilValidate.isNotEmpty(billingAddressId)) { GenericValue orderCm = delegator.makeValue("OrderContactMech", null); orderCm.set("contactMechPurposeTypeId", "BILLING_LOCATION"); orderCm.set("contactMechId", billingAddressId); values.add(orderCm); } } // create the OrderPaymentPreference record GenericValue opp = delegator.makeValue("OrderPaymentPreference", new HashMap()); opp.set("paymentMethodTypeId", valueObj.getString("paymentMethodTypeId")); opp.set("presentFlag", isPresent ? "Y" : "N"); opp.set("overflowFlag", overflow ? "Y" : "N"); opp.set("paymentMethodId", paymentMethodId); opp.set("billingPostalCode", postalCode); opp.set("maxAmount", amount); if (refNum != null) { opp.set("manualRefNum", refNum[0]); opp.set("manualAuthCode", refNum[1]); } if (securityCode != null) { opp.set("securityCode", securityCode); } if (paymentMethodId != null) { opp.set("statusId", "PAYMENT_NOT_AUTH"); } else if (paymentMethodTypeId != null) { // external payment method types require notification when received // internal payment method types are assumed to be in-hand if (paymentMethodTypeId.startsWith("EXT_")) { opp.set("statusId", "PAYMENT_NOT_RECEIVED"); } else { opp.set("statusId", "PAYMENT_RECEIVED"); } } Debug.log("Creating OrderPaymentPreference - " + opp, module); values.add(opp); } return values; } public int compareTo(Object o) { CartPaymentInfo that = (CartPaymentInfo) o; Debug.logInfo("Compare [" + this.toString() + "] to [" + that.toString() + "]", module); if (this.paymentMethodId != null) { if (that.paymentMethodId == null) { return 1; } else { int pmCmp = this.paymentMethodId.compareTo(that.paymentMethodId); if (pmCmp == 0) { if (this.refNum != null && this.refNum[0] != null) { if (that.refNum != null && that.refNum[0] != null) { return this.refNum[0].compareTo(that.refNum[0]); } else { return 1; } } else { if (that.refNum != null && that.refNum[0] != null) { return -1; } else { return 0; } } } else { return pmCmp; } } } else { if (that.paymentMethodId != null) { return -1; } else { int pmtCmp = this.paymentMethodTypeId.compareTo(that.paymentMethodTypeId); if (pmtCmp == 0) { if (this.refNum != null && this.refNum[0] != null) { if (that.refNum != null && that.refNum[0] != null) { return this.refNum[0].compareTo(that.refNum[0]); } else { return 1; } } else { if (that.refNum != null && that.refNum[0] != null) { return -1; } else { return 0; } } } else { return pmtCmp; } } } } public String toString() { return "Pm: " + paymentMethodId + " / PmType: " + paymentMethodTypeId + " / Amt: " + amount + " / Ref: " + refNum[0] + "!" + refNum[1]; } } /** Contains a List for each productPromoId (key) containing a productPromoCodeId (or empty string for no code) for each use of the productPromoId */ private List productPromoUseInfoList = new LinkedList(); /** Contains the promo codes entered */ private Set productPromoCodes = new HashSet(); private List freeShippingProductPromoActions = new ArrayList(); /** Note that even though this is promotion info, it should NOT be cleared when the promos are cleared, it is a preference that will be used in the next promo calculation */ private Map desiredAlternateGiftByAction = new HashMap(); private Timestamp cartCreatedTs = UtilDateTime.nowTimestamp(); private transient GenericDelegator delegator = null; private String delegatorName = null; protected String productStoreId = null; protected String transactionId = null; protected String facilityId = null; protected String webSiteId = null; protected String terminalId = null; /** General partyId for the Order, all other IDs default to this one if not specified explicitly */ protected String orderPartyId = null; // sales order parties protected String placingCustomerPartyId = null; protected String billToCustomerPartyId = null; protected String shipToCustomerPartyId = null; protected String endUserCustomerPartyId = null; // purchase order parties protected String billFromVendorPartyId = null; protected String shipFromVendorPartyId = null; protected String supplierAgentPartyId = null; protected GenericValue userLogin = null; protected GenericValue autoUserLogin = null; protected Locale locale; // holds the locale from the user session protected String currencyUom = null; protected boolean holdOrder = false; protected Timestamp orderDate = null; /** don't allow empty constructor */ protected ShoppingCart() {} /** Creates a new cloned ShoppingCart Object. */ public ShoppingCart(ShoppingCart cart) { this.delegator = cart.getDelegator(); this.delegatorName = delegator.getDelegatorName(); this.productStoreId = cart.getProductStoreId(); this.poNumber = cart.getPoNumber(); this.orderId = cart.getOrderId(); this.firstAttemptOrderId = cart.getFirstAttemptOrderId(); this.billingAccountId = cart.getBillingAccountId(); this.agreementId = cart.getAgreementId(); this.quoteId = cart.getQuoteId(); this.orderAdditionalEmails = cart.getOrderAdditionalEmails(); this.adjustments = new LinkedList(cart.getAdjustments()); this.contactMechIdsMap = new HashMap(cart.getOrderContactMechIds()); this.freeShippingProductPromoActions = new ArrayList(cart.getFreeShippingProductPromoActions()); this.desiredAlternateGiftByAction = cart.getAllDesiredAlternateGiftByActionCopy(); this.productPromoUseInfoList = new LinkedList(cart.productPromoUseInfoList); this.productPromoCodes = new HashSet(cart.productPromoCodes); this.locale = cart.getLocale(); this.currencyUom = cart.getCurrency(); this.externalId = cart.getExternalId(); this.internalCode = cart.getInternalCode(); this.viewCartOnAdd = cart.viewCartOnAdd(); this.defaultShipAfterDate = cart.getDefaultShipAfterDate(); this.defaultShipBeforeDate = cart.getDefaultShipBeforeDate(); // clone the additionalPartyRoleMap this.additionalPartyRole = new HashMap(); Iterator it = cart.additionalPartyRole.entrySet().iterator(); while (it.hasNext()) { Map.Entry me = (Map.Entry) it.next(); this.additionalPartyRole.put(me.getKey(), new LinkedList((Collection) me.getValue())); } // clone the items List items = cart.items(); Iterator itIt = items.iterator(); while (itIt.hasNext()) { cartLines.add(new ShoppingCartItem((ShoppingCartItem) itIt.next())); } } /** Creates new empty ShoppingCart object. */ public ShoppingCart(GenericDelegator delegator, String productStoreId, String webSiteId, Locale locale, String currencyUom, String billToCustomerPartyId, String billFromVendorPartyId) { this.delegator = delegator; this.delegatorName = delegator.getDelegatorName(); this.productStoreId = productStoreId; this.webSiteId = webSiteId; this.currencyUom = currencyUom; this.locale = locale; if (this.locale == null) { this.locale = Locale.getDefault(); } if (productStoreId == null) { throw new IllegalArgumentException("productStoreId cannot be null"); } // set the default view cart on add for this store GenericValue productStore = ProductStoreWorker.getProductStore(productStoreId, delegator); if (productStore == null) { throw new IllegalArgumentException("Unable to locate ProductStore by ID [" + productStoreId + "]"); } String storeViewCartOnAdd = productStore.getString("viewCartOnAdd"); if (storeViewCartOnAdd != null && "Y".equalsIgnoreCase(storeViewCartOnAdd)) { this.viewCartOnAdd = true; } if (billFromVendorPartyId == null) { // since default cart is of type SALES_ORDER, set to store's payToPartyId this.billFromVendorPartyId = productStore.getString("payToPartyId"); } else { this.billFromVendorPartyId = billFromVendorPartyId; } this.billToCustomerPartyId = billToCustomerPartyId;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -