📄 shoppingcartitem.java
字号:
}
public void removeAdjustment(int index) {
itemAdjustments.remove(index);
}
public List getAdjustments() {
return itemAdjustments;
}
public void removeFeatureAdjustment(String productFeatureId) {
if (productFeatureId == null) return;
Iterator itemAdjustmentsIter = itemAdjustments.iterator();
while (itemAdjustmentsIter.hasNext()) {
GenericValue itemAdjustment = (GenericValue) itemAdjustmentsIter.next();
if (productFeatureId.equals(itemAdjustment.getString("productFeatureId"))) {
itemAdjustmentsIter.remove();
}
}
}
public List getOrderItemPriceInfos() {
return orderItemPriceInfos;
}
/** 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 item given the contactMechPurposeTypeId */
public String getContactMech(String contactMechPurposeTypeId) {
return (String) contactMechIdsMap.get(contactMechPurposeTypeId);
}
/** Remove the contactMechId from this item given the contactMechPurposeTypeId */
public String removeContactMech(String contactMechPurposeTypeId) {
return (String) contactMechIdsMap.remove(contactMechPurposeTypeId);
}
public Map getOrderItemContactMechIds() {
return contactMechIdsMap;
}
public void setIsPromo(boolean isPromo) {
this.isPromo = isPromo;
}
public boolean getIsPromo() {
return this.isPromo;
}
public GenericValue getOrderShipmentPreference() {
return orderShipmentPreference;
}
/** 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 void setCarrierPartyId(String carrierPartyId) {
orderShipmentPreference.set("carrierPartyId", carrierPartyId);
}
public String getCarrierPartyId() {
return orderShipmentPreference.getString("carrierPartyId");
}
/** Compares the specified object with this cart item. */
public boolean equals(ShoppingCartItem item) {
if (item == null) return false;
return this.equals(item.getProductId(), item.additionalProductFeatureAndAppls, item.attributes, item.prodCatalogId, item.selectedAmount, item.getIsPromo());
}
/** Compares the specified object with this cart item. Defaults isPromo to false. */
public boolean equals(String productId, Map additionalProductFeatureAndAppls, Map attributes, String prodCatalogId, double selectedAmount) {
return equals(productId, additionalProductFeatureAndAppls, attributes, prodCatalogId, selectedAmount, false);
}
/** Compares the specified object with this cart item. */
public boolean equals(String productId, Map additionalProductFeatureAndAppls, Map attributes, String prodCatalogId, double selectedAmount, boolean isPromo) {
if (this.productId == null || productId == null) {
// all non-product items are unique
return false;
}
if (!this.productId.equals(productId)) {
return false;
}
if ((this.prodCatalogId == null && prodCatalogId != null) || (this.prodCatalogId != null && prodCatalogId == null)) {
return false;
}
if (this.prodCatalogId != null && prodCatalogId != null && !this.prodCatalogId.equals(prodCatalogId)) {
return false;
}
if (this.getSelectedAmount() != selectedAmount) {
return false;
}
if (this.isPromo != isPromo) {
return false;
}
if ((this.additionalProductFeatureAndAppls != null && additionalProductFeatureAndAppls != null) &&
(this.additionalProductFeatureAndAppls.size() != additionalProductFeatureAndAppls.size()) &&
!(this.additionalProductFeatureAndAppls.equals(additionalProductFeatureAndAppls))) {
return false;
}
if ((this.attributes != null && attributes != null) &&
(this.attributes.size() != attributes.size()) &&
!(this.attributes.equals(attributes))) {
return false;
}
return true;
}
/** Gets the Product entity. If it is not already retreived gets it from the delegator */
public GenericValue getProduct() {
if (this._product != null) {
return this._product;
}
if (this.productId != null) {
try {
this._product = this.getDelegator().findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId));
} catch (GenericEntityException e) {
throw new RuntimeException("Entity Engine error getting Product (" + e.getMessage() + ")");
}
}
return this._product;
}
public GenericValue getParentProduct() {
if (this._parentProduct != null) {
return this._parentProduct;
}
if (this.productId == null) {
throw new IllegalStateException("Bad product id");
}
try {
List virtualProductAssocs = this.getDelegator().findByAndCache("ProductAssoc", UtilMisc.toMap("productIdTo", productId, "productAssocTypeId", "PRODUCT_VARIANT"), UtilMisc.toList("-fromDate"));
virtualProductAssocs = EntityUtil.filterByDate(virtualProductAssocs, true);
if (virtualProductAssocs == null || virtualProductAssocs.size() == 0) {
//okay, not a variant, try a UNIQUE_ITEM
virtualProductAssocs = this.getDelegator().findByAndCache("ProductAssoc", UtilMisc.toMap("productIdTo", productId, "productAssocTypeId", "UNIQUE_ITEM"), UtilMisc.toList("-fromDate"));
virtualProductAssocs = EntityUtil.filterByDate(virtualProductAssocs, true);
}
if (virtualProductAssocs != null && virtualProductAssocs.size() > 0) {
//found one, set this first as the parent product
GenericValue productAssoc = EntityUtil.getFirst(virtualProductAssocs);
this._parentProduct = productAssoc.getRelatedOneCache("MainProduct");
}
} catch (GenericEntityException e) {
throw new RuntimeException("Entity Engine error getting Parent Product (" + e.getMessage() + ")");
}
return this._parentProduct;
}
public String getParentProductId() {
GenericValue parentProduct = this.getParentProduct();
if (parentProduct != null) {
return parentProduct.getString("productId");
} else {
return null;
}
}
public Map getOptionalProductFeatures() {
if (_product != null) {
return ProductWorker.getOptionalProductFeatures(getDelegator(), this.productId);
} else {
// non-product items do not have features
return new HashMap();
}
}
public GenericDelegator getDelegator() {
if (delegator == null) {
if (UtilValidate.isEmpty(delegatorName)) {
throw new IllegalStateException("Bad delegator name");
}
delegator = GenericDelegator.getGenericDelegator(delegatorName);
}
return delegator;
}
public void explodeItem(ShoppingCart cart, LocalDispatcher dispatcher) throws CartItemModifyException {
double baseQuantity = this.getQuantity();
int thisIndex = cart.items().indexOf(this);
List newItems = new ArrayList();
if (baseQuantity > 1) {
for (int i = 1; i < baseQuantity; i++) {
// clone the item
ShoppingCartItem item = new ShoppingCartItem(this);
// set the new item's quantity
item.setQuantity(1, dispatcher, cart, false);
// now copy/calc the adjustments
Debug.logInfo("Clone's adj: " + item.getAdjustments(), module);
if (item.getAdjustments() != null && item.getAdjustments().size() > 0) {
List adjustments = new LinkedList(item.getAdjustments());
Iterator adjIterator = adjustments.iterator();
while (adjIterator.hasNext()) {
GenericValue adjustment = (GenericValue) adjIterator.next();
if (adjustment != null) {
item.removeAdjustment(adjustment);
GenericValue newAdjustment = new GenericValue(adjustment);
Double adjAmount = newAdjustment.getDouble("amount");
// we use != becuase adjustments can be +/-
if (adjAmount != null && adjAmount.doubleValue() != 0.00)
newAdjustment.set("amount", new Double(adjAmount.doubleValue() / baseQuantity));
Debug.logInfo("Cloned adj: " + newAdjustment, module);
item.addAdjustment(newAdjustment);
} else {
Debug.logInfo("Clone Adjustment is null", module);
}
}
}
newItems.add(item);
}
// set this item's quantity
this.setQuantity(1, dispatcher, cart, false);
Debug.logInfo("BaseQuantity: " + baseQuantity, module);
Debug.logInfo("Item's Adj: " + this.getAdjustments(), module);
// re-calc this item's adjustments
if (this.getAdjustments() != null && this.getAdjustments().size() > 0) {
List adjustments = new LinkedList(this.getAdjustments());
Iterator adjIterator = adjustments.iterator();
while (adjIterator.hasNext()) {
GenericValue adjustment = (GenericValue) adjIterator.next();
if (adjustment != null) {
this.removeAdjustment(adjustment);
GenericValue newAdjustment = new GenericValue(adjustment);
Double adjAmount = newAdjustment.getDouble("amount");
// we use != becuase adjustments can be +/-
if (adjAmount != null && adjAmount.doubleValue() != 0.00)
newAdjustment.set("amount", new Double(adjAmount.doubleValue() / baseQuantity));
Debug.logInfo("Updated adj: " + newAdjustment, module);
this.addAdjustment(newAdjustment);
}
}
}
// add the cloned item(s) to the cart
Iterator newItemsItr = newItems.iterator();
while (newItemsItr.hasNext()) {
cart.addItem(thisIndex, (ShoppingCartItem) newItemsItr.next());
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -