Author: hansbak
Date: Fri Dec 9 07:20:28 2011 New Revision: 1212266 URL: http://svn.apache.org/viewvc?rev=1212266&view=rev Log: now possible to add comments when adding a product to the cart which are stored in orderitem attributes and displayed in the shopping cart and order. Possible to switch off in order.properties Modified: ofbiz/trunk/applications/order/config/order.properties ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java ofbiz/trunk/applications/order/webapp/ordermgr/order/orderitems.ftl ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/cart/showcart.ftl ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/catalog/productdetail.ftl ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/order/orderitems.ftl Modified: ofbiz/trunk/applications/order/config/order.properties URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/config/order.properties?rev=1212266&r1=1212265&r2=1212266&view=diff ============================================================================== --- ofbiz/trunk/applications/order/config/order.properties (original) +++ ofbiz/trunk/applications/order/config/order.properties Fri Dec 9 07:20:28 2011 @@ -22,3 +22,7 @@ daysTillCancelReplacementOrder=30 # Maximum age of auto-save shopping list for anonymous users (in days) autosave.max.age=14 + +# Order Item Attribute +order.item.attr.prefix=order_item_attr_ +order.item.comment.enable=Y Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java?rev=1212266&r1=1212265&r2=1212266&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Fri Dec 9 07:20:28 2011 @@ -49,6 +49,7 @@ import java.math.BigDecimal; import java.math.MathContext; import java.sql.Timestamp; import java.util.*; +import java.util.Map.Entry; /** * Shopping Cart Object @@ -489,6 +490,14 @@ public class ShoppingCart implements Ite String accommodationMapId, String accommodationSpotId, Timestamp shipBeforeDate, Timestamp shipAfterDate, Map<String, GenericValue> features, Map<String, Object> attributes, String prodCatalogId, ProductConfigWrapper configWrapper, String itemType, String itemGroupNumber, String parentProductId, LocalDispatcher dispatcher) throws CartItemModifyException, ItemNotFoundException { + return addOrIncreaseItem(productId, selectedAmount, quantity, reservStart, reservLength, reservPersons, accommodationMapId, accommodationSpotId, shipBeforeDate, shipAfterDate, features, attributes, null, prodCatalogId, configWrapper, itemType, itemGroupNumber, parentProductId, dispatcher); + } + + /** add rental (with accommodation) item to cart and order item attributes*/ + public int addOrIncreaseItem(String productId, BigDecimal selectedAmount, BigDecimal quantity, Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersons, + String accommodationMapId, String accommodationSpotId, + Timestamp shipBeforeDate, Timestamp shipAfterDate, Map<String, GenericValue> features, Map<String, Object> attributes, Map<String, String> orderItemAttributes, String prodCatalogId, + ProductConfigWrapper configWrapper, String itemType, String itemGroupNumber, String parentProductId, LocalDispatcher dispatcher) throws CartItemModifyException, ItemNotFoundException { if (isReadOnlyCart()) { throw new CartItemModifyException("Cart items cannot be changed"); } @@ -504,7 +513,7 @@ public class ShoppingCart implements Ite ShoppingCartItem sci = cartLines.get(i); - if (sci.equals(productId, reservStart, reservLength, reservPersons, accommodationMapId, accommodationSpotId, features, attributes, prodCatalogId,selectedAmount, configWrapper, itemType, itemGroup, false)) { + if (sci.equals(productId, reservStart, reservLength, reservPersons, accommodationMapId, accommodationSpotId, features, attributes, orderItemAttributes, prodCatalogId,selectedAmount, configWrapper, itemType, itemGroup, false)) { BigDecimal newQuantity = sci.getQuantity().add(quantity); try { BigDecimal minQuantity = getMinimumOrderQuantity(getDelegator(),sci.getBasePrice(), productId); @@ -542,11 +551,12 @@ public class ShoppingCart implements Ite } } // Add the new item to the shopping cart if it wasn't found. + ShoppingCartItem item = null; if (getOrderType().equals("PURCHASE_ORDER")) { //GenericValue productSupplier = null; supplierProduct = getSupplierProduct(productId, quantity, dispatcher); if (supplierProduct != null || "_NA_".equals(this.getPartyId())) { - return this.addItem(0, ShoppingCartItem.makePurchaseOrderItem(Integer.valueOf(0), productId, selectedAmount, quantity, features, attributes, prodCatalogId, configWrapper, itemType, itemGroup, dispatcher, this, supplierProduct, shipBeforeDate, shipAfterDate, cancelBackOrderDate)); + item = ShoppingCartItem.makePurchaseOrderItem(Integer.valueOf(0), productId, selectedAmount, quantity, features, attributes, prodCatalogId, configWrapper, itemType, itemGroup, dispatcher, this, supplierProduct, shipBeforeDate, shipAfterDate, cancelBackOrderDate); } else { throw new CartItemModifyException("SupplierProduct not found"); } @@ -559,11 +569,18 @@ public class ShoppingCart implements Ite } catch (GenericEntityException e) { Debug.logError(e, module); } - return this.addItem(0, ShoppingCartItem.makeItem(Integer.valueOf(0), productId, selectedAmount, quantity, null, + item = ShoppingCartItem.makeItem(Integer.valueOf(0), productId, selectedAmount, quantity, null, reservStart, reservLength, reservPersons, accommodationMapId, accommodationSpotId, shipBeforeDate, shipAfterDate, features, attributes, prodCatalogId, configWrapper, itemType, itemGroup, dispatcher, - this, Boolean.TRUE, Boolean.TRUE, parentProductId, Boolean.FALSE, Boolean.FALSE)); + this, Boolean.TRUE, Boolean.TRUE, parentProductId, Boolean.FALSE, Boolean.FALSE); + } + // add order item attributes + for (Entry<String, String> entry : orderItemAttributes.entrySet()) { + item.setOrderItemAttribute(entry.getKey(), entry.getValue()); } + + return this.addItem(0, item); + } /** Add a non-product item to the shopping cart. Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java?rev=1212266&r1=1212265&r2=1212266&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java Fri Dec 9 07:20:28 2011 @@ -29,6 +29,7 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import javolution.util.FastMap; @@ -229,6 +230,15 @@ public class ShoppingCartHelper { } } + // get order item attributes + Map<String, String> orderItemAttributes = FastMap.newInstance(); + String orderItemAttributePrefix = UtilProperties.getPropertyValue("order.properties", "order.item.attr.prefix"); + for (Entry<String, ? extends Object> entry : context.entrySet()) { + if (entry.getKey().toString().contains(orderItemAttributePrefix) && UtilValidate.isNotEmpty(entry.getValue())) { + orderItemAttributes.put(entry.getKey().replaceAll(orderItemAttributePrefix, ""), entry.getValue().toString()); + } + } + // add or increase the item to the cart int itemId = -1; try { @@ -236,7 +246,7 @@ public class ShoppingCartHelper { itemId = cart.addOrIncreaseItem(productId, amount, quantity, reservStart, reservLength, reservPersons, accommodationMapId, accommodationSpotId, shipBeforeDate, shipAfterDate, additionalFeaturesMap, attributes, - catalogId, configWrapper, itemType, itemGroupNumber, pProductId, dispatcher); + orderItemAttributes, catalogId, configWrapper, itemType, itemGroupNumber, pProductId, dispatcher); } else { itemId = cart.addNonProductItem(itemType, itemDescription, productCategoryId, price, quantity, attributes, catalogId, itemGroupNumber, dispatcher); Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java?rev=1212266&r1=1212265&r2=1212266&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java Fri Dec 9 07:20:28 2011 @@ -2360,6 +2360,13 @@ public class ShoppingCartItem implements public boolean equals(String productId, Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersons, String accommodationMapId, String accommodationSpotId, Map<String, GenericValue> additionalProductFeatureAndAppls, Map<String, Object> attributes, String prodCatalogId, BigDecimal selectedAmount, ProductConfigWrapper configWrapper, String itemType, ShoppingCart.ShoppingCartItemGroup itemGroup, boolean isPromo) { + return equals(productId, reservStart, reservLength, reservPersons, accommodationMapId, accommodationSpotId, additionalProductFeatureAndAppls, attributes, null, prodCatalogId, selectedAmount, configWrapper, itemType, itemGroup, isPromo); + } + + /** Compares the specified object order item attributes. */ + public boolean equals(String productId, Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersons, String accommodationMapId, String accommodationSpotId, + Map<String, GenericValue> additionalProductFeatureAndAppls, Map<String, Object> attributes, Map<String, String> orderItemAttributes, String prodCatalogId, BigDecimal selectedAmount, + ProductConfigWrapper configWrapper, String itemType, ShoppingCart.ShoppingCartItemGroup itemGroup, boolean isPromo) { if (this.productId == null || productId == null) { // all non-product items are unique return false; @@ -2440,6 +2447,12 @@ public class ShoppingCartItem implements return false; } + if ((this.orderItemAttributes == null && UtilValidate.isNotEmpty(orderItemAttributes)) || (UtilValidate.isNotEmpty(this.orderItemAttributes) && orderItemAttributes == null) || + (this.orderItemAttributes != null && orderItemAttributes != null && (this.orderItemAttributes.size() != orderItemAttributes.size() || !(this.orderItemAttributes.equals(orderItemAttributes))))) { + // order item attribute unique + return false; + } + return true; } Modified: ofbiz/trunk/applications/order/webapp/ordermgr/order/orderitems.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/order/orderitems.ftl?rev=1212266&r1=1212265&r2=1212266&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/order/orderitems.ftl (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/order/orderitems.ftl Fri Dec 9 07:20:28 2011 @@ -69,6 +69,16 @@ under the License. <#else> ${orderItem.itemDescription?if_exists} </#if> + <#assign orderItemAttributes = orderItem.getRelated("OrderItemAttribute")/> + <#if orderItemAttributes?has_content> + <ul> + <#list orderItemAttributes as orderItemAttribute> + <li> + ${orderItemAttribute.attrName} : ${orderItemAttribute.attrValue} + </li> + </#list> + </ul> + </#if> </div> <div style="float:right;"> <a href="/catalog/control/EditProduct?productId=${productId}${externalKeyParam}" class="buttontext" target="_blank">${uiLabelMap.ProductCatalog}</a> @@ -718,4 +728,3 @@ under the License. </div> </div> </#if> - Modified: ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/cart/showcart.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/cart/showcart.ftl?rev=1212266&r1=1212265&r2=1212266&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/cart/showcart.ftl (original) +++ ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/cart/showcart.ftl Fri Dec 9 07:20:28 2011 @@ -272,7 +272,17 @@ function setAlternateGwp(field) { <#-- this is a non-product item --> ${cartLine.getItemTypeDescription()?if_exists}: ${cartLine.getName()?if_exists} </#if> - + <#assign attrs = cartLine.getOrderItemAttributes()/> + <#if attrs?has_content> + <#assign attrEntries = attrs.entrySet()/> + <ul> + <#list attrEntries as attrEntry> + <li> + ${attrEntry.getKey()} : ${attrEntry.getValue()} + </li> + </#list> + </ul> + </#if> <#if (cartLine.getIsPromo() && cartLine.getAlternativeOptionProductIds()?has_content)> <#-- Show alternate gifts if there are any... --> <div class="tableheadtext">${uiLabelMap.OrderChooseFollowingForGift}:</div> Modified: ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/catalog/productdetail.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/catalog/productdetail.ftl?rev=1212266&r1=1212265&r2=1212266&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/catalog/productdetail.ftl (original) +++ ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/catalog/productdetail.ftl Fri Dec 9 07:20:28 2011 @@ -541,6 +541,11 @@ ${virtualVariantJavaScript?if_exists} <form method="post" action="<@ofbizUrl>additem</@ofbizUrl>" name="addform" style="margin: 0;"> <fieldset> <#assign inStock = true /> + <#assign commentEnable = Static["org.ofbiz.base.util.UtilProperties"].getPropertyValue("order.properties", "order.item.comment.enable")> + <#if commentEnable.equals("Y")> + <#assign orderItemAttr = Static["org.ofbiz.base.util.UtilProperties"].getPropertyValue("order.properties", "order.item.attr.prefix")> + ${uiLabelMap.CommonComment} <input type="text" name="${orderItemAttr}comment"/> + </#if> <#-- Variant Selection --> <#if product.isVirtual?if_exists?upper_case == "Y"> <#if product.virtualVariantMethodEnum?if_exists == "VV_FEATURETREE" && featureLists?has_content> Modified: ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/order/orderitems.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/order/orderitems.ftl?rev=1212266&r1=1212265&r2=1212266&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/order/orderitems.ftl (original) +++ ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/order/orderitems.ftl Fri Dec 9 07:20:28 2011 @@ -123,6 +123,16 @@ under the License. <#assign product = orderItem.getRelatedOneCache("Product")?if_exists/> <#-- should always exist because of FK constraint, but just in case --> <td > <a href="<@ofbizCatalogAltUrl fullPath="true" secure="false" productId=orderItem.productId/>" class="linktext">${orderItem.productId} - ${orderItem.itemDescription?default("")}</a> + <#assign orderItemAttributes = orderItem.getRelated("OrderItemAttribute")/> + <#if orderItemAttributes?has_content> + <ul> + <#list orderItemAttributes as orderItemAttribute> + <li> + ${orderItemAttribute.attrName} : ${orderItemAttribute.attrValue} + </li> + </#list> + </ul> + </#if> <#if product?has_content> <#if product.piecesIncluded?exists && product.piecesIncluded?long != 0> [${uiLabelMap.OrderPieces}: ${product.piecesIncluded}] |
Free forum by Nabble | Edit this page |