📄 shoppingcart.java
字号:
/** Returns the amount to be billed to the billing account.*/
public double getBillingAccountAmount() {
return this.billingAccountAmt;
}
/** Sets the shipping contact mech id. */
public void setShippingContactMechId(String shippingContactMechId) {
// set the shipping address
this.addContactMech("SHIPPING_LOCATION", shippingContactMechId);
}
/** Returns the shipping message string. */
public String getShippingContactMechId() {
return this.getContactMech("SHIPPING_LOCATION");
}
/** Returns the order level shipping amount */
public double getOrderShipping() {
return OrderReadHelper.calcOrderAdjustments(this.getAdjustments(), this.getSubTotal(), false, false, true);
}
/** Sets the shipment method type. */
public void setShipmentMethodTypeId(String shipmentMethodTypeId) {
orderShipmentPreference.set("shipmentMethodTypeId", shipmentMethodTypeId);
}
/** Returns the shipment method type */
public String getShipmentMethodTypeId() {
return orderShipmentPreference.getString("shipmentMethodTypeId");
}
/** Sets the shipping instructions. */
public void setShippingInstructions(String shippingInstructions) {
orderShipmentPreference.set("shippingInstructions", shippingInstructions);
}
/** Returns the shipping instructions. */
public String getShippingInstructions() {
return orderShipmentPreference.getString("shippingInstructions");
}
public void setMaySplit(Boolean maySplit) {
orderShipmentPreference.set("maySplit", maySplit);
}
/** Returns Boolean.TRUE if the order may be split (null if unspecified) */
public Boolean getMaySplit() {
return orderShipmentPreference.getBoolean("maySplit");
}
public void setGiftMessage(String giftMessage) {
orderShipmentPreference.set("giftMessage", giftMessage);
}
public String getGiftMessage() {
return orderShipmentPreference.getString("giftMessage");
}
public void setIsGift(Boolean isGift) {
orderShipmentPreference.set("isGift", isGift);
}
public Boolean getIsGift() {
return orderShipmentPreference.getBoolean("isGift");
}
public GenericValue getOrderShipmentPreference() {
return this.orderShipmentPreference;
}
public void setCarrierPartyId(String carrierPartyId) {
orderShipmentPreference.set("carrierPartyId", carrierPartyId);
}
public String getCarrierPartyId() {
return orderShipmentPreference.getString("carrierPartyId");
}
public void setOrderAdditionalEmails(String orderAdditionalEmails) {
this.orderAdditionalEmails = orderAdditionalEmails;
}
public String getOrderAdditionalEmails() {
return orderAdditionalEmails;
}
public List getPaymentMethods() {
List paymentMethods = new LinkedList();
if (paymentMethodIds != null && paymentMethodIds.size() > 0) {
Iterator pmIdsIter = paymentMethodIds.iterator();
while (pmIdsIter.hasNext()) {
String paymentMethodId = (String) pmIdsIter.next();
try {
paymentMethods.add(getDelegator().findByPrimaryKey("PaymentMethod", UtilMisc.toMap("paymentMethodId", paymentMethodId)));
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
}
}
return paymentMethods;
}
public List getGiftCards() {
List paymentMethods = this.getPaymentMethods();
List giftCards = new LinkedList();
if (paymentMethods != null) {
Iterator i = paymentMethods.iterator();
while (i.hasNext()) {
GenericValue pm = (GenericValue) i.next();
if ("GIFT_CARD".equals(pm.getString("paymentMethodTypeId"))) {
try {
GenericValue gc = pm.getRelatedOne("GiftCard");
giftCards.add(gc);
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get gift card record from payment method : " + pm, module);
}
}
}
}
return giftCards;
}
public GenericValue getShippingAddress() {
if (this.getShippingContactMechId() != null) {
try {
return getDelegator().findByPrimaryKey("PostalAddress", UtilMisc.toMap("contactMechId", this.getShippingContactMechId()));
} catch (GenericEntityException e) {
Debug.logWarning(e.toString(), module);
return null;
}
} else {
return null;
}
}
/** Returns the tax amount from the cart object. */
public double getTotalSalesTax() {
double tempTax = 0.0;
Iterator i = iterator();
while (i.hasNext()) {
tempTax += ((ShoppingCartItem) i.next()).getItemTax();
}
tempTax += OrderReadHelper.calcOrderAdjustments(this.getAdjustments(), getSubTotal(), false, true, false);
return tempTax;
}
/** Returns the shipping amount from the cart object. */
public double getTotalShipping() {
double tempShipping = 0.0;
Iterator i = iterator();
while (i.hasNext()) {
tempShipping += ((ShoppingCartItem) i.next()).getItemShipping();
}
tempShipping += OrderReadHelper.calcOrderAdjustments(this.getAdjustments(), getSubTotal(), false, false, true);
return tempShipping;
}
/** Returns the item-total in the cart (not including discount/tax/shipping). */
public double getItemTotal() {
double itemTotal = 0.00;
Iterator i = iterator();
while (i.hasNext()) {
itemTotal += ((ShoppingCartItem) i.next()).getBasePrice();
}
return itemTotal;
}
/** Returns the sub-total in the cart (item-total - discount). */
public double getSubTotal() {
double itemsTotal = 0.00;
Iterator i = iterator();
while (i.hasNext()) {
itemsTotal += ((ShoppingCartItem) i.next()).getItemSubTotal();
}
return itemsTotal;
}
/** Returns the sub-total in the cart (item-total - discount). */
public double getSubTotalForPromotions() {
double itemsTotal = 0.00;
Iterator i = iterator();
while (i.hasNext()) {
ShoppingCartItem cartItem = (ShoppingCartItem) i.next();
GenericValue product = cartItem.getProduct();
if (product != null && "N".equals(product.getString("includeInPromotions"))) {
// don't include in total if this is the case...
continue;
}
itemsTotal += cartItem.getItemSubTotal();
}
return itemsTotal;
}
/** Add a contact mech to this purpose; the contactMechPurposeTypeId is required */
public void addContactMech(String contactMechPurposeTypeId, String contactMechId) {
if (contactMechPurposeTypeId == null) throw new IllegalArgumentException("You must specify a contactMechPurposeTypeId to add a ContactMech");
contactMechIdsMap.put(contactMechPurposeTypeId, contactMechId);
}
/** Get the contactMechId for this cart given the contactMechPurposeTypeId */
public String getContactMech(String contactMechPurposeTypeId) {
return (String) contactMechIdsMap.get(contactMechPurposeTypeId);
}
/** Remove the contactMechId from this cart given the contactMechPurposeTypeId */
public String removeContactMech(String contactMechPurposeTypeId) {
return (String) contactMechIdsMap.remove(contactMechPurposeTypeId);
}
public Map getOrderContactMechIds() {
return this.contactMechIdsMap;
}
/** Get a List of adjustments on the order (ie cart) */
public List getAdjustments() {
return adjustments;
}
/** Add an adjustment to the order; don't worry about setting the orderId, orderItemSeqId or orderAdjustmentId; they will be set when the order is created */
public void addAdjustment(GenericValue adjustment) {
adjustments.add(adjustment);
}
public void removeAdjustment(int index) {
adjustments.remove(index);
}
/** go through the order adjustments and remove all adjustments with the given type */
public void removeAdjustmentByType(String orderAdjustmentTypeId) {
if (orderAdjustmentTypeId == null) return;
// make a list of adjustment lists including the cart adjustments and the cartItem adjustments for each item
List adjsLists = new LinkedList();
if (this.getAdjustments() != null) {
adjsLists.add(this.getAdjustments());
}
Iterator cartIterator = this.iterator();
while (cartIterator.hasNext()) {
ShoppingCartItem item = (ShoppingCartItem) cartIterator.next();
if (item.getAdjustments() != null) {
adjsLists.add(item.getAdjustments());
}
}
Iterator adjsListsIter = adjsLists.iterator();
while (adjsListsIter.hasNext()) {
List adjs = (List) adjsListsIter.next();
if (adjs != null) {
for (int i = 0; i < adjs.size();) {
GenericValue orderAdjustment = (GenericValue) adjs.get(i);
if (orderAdjustmentTypeId.equals(orderAdjustment.getString("orderAdjustmentTypeId"))) {
adjs.remove(i);
} else {
i++;
}
}
}
}
}
public double getOrderOtherAdjustmentTotal() {
return OrderReadHelper.calcOrderAdjustments(this.getAdjustments(), getSubTotal(), true, false, false);
}
/** Returns the total from the cart, including tax/shipping. */
public double getGrandTotal() {
List orderAdjustments = this.makeAllAdjustments();
List orderItems = this.makeOrderItems();
return OrderReadHelper.getOrderGrandTotal(orderItems, orderAdjustments);
}
/** Returns the SHIPPABLE item-total in the cart. */
public double getShippableTotal() {
double itemTotal = 0.0;
Iterator i = iterator();
while (i.hasNext()) {
ShoppingCartItem item = (ShoppingCartItem) i.next();
if (item.shippingApplies())
itemTotal += item.getItemSubTotal();
}
return itemTotal;
}
/** Returns the total quantity in the cart. */
public double getTotalQuantity() {
double count = 0.0;
Iterator i = iterator();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -