Author: mridulpathak
Date: Sat Jun 18 12:08:06 2016
New Revision: 1748969
URL: http://svn.apache.org/viewvc?rev=1748969&view=rev
Log:
[OFBIZ-6940] Thanks Vishal Chhabria for your contribution and Jacopo for review.
New ProductPriceType 'SHIPPING_ALLOWANCE' and a new minimumPrice field in
ProductStoreShipmentMeth entity.
========================================
New price type "SHIPPING_ALLOWANCE" can be used in the scenarios where
default/list prices are comprehensive of the 'Shipping Cost' quota, this price
type can help user to set the Shipping Allowance cost he has included in the
the product's default/list price and then modify actual shipping cost by
reducing the allowance cost from it.
minimumPrice field can be used to set the the lowest rate for a particular
shipping type.
Modified:
ofbiz/trunk/applications/datamodel/entitydef/product-entitymodel.xml
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEvents.java
ofbiz/trunk/applications/product/data/ProductTypeData.xml
Modified: ofbiz/trunk/applications/datamodel/entitydef/product-entitymodel.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/datamodel/entitydef/product-entitymodel.xml?rev=1748969&r1=1748968&r2=1748969&view=diff
==============================================================================
--- ofbiz/trunk/applications/datamodel/entitydef/product-entitymodel.xml
(original)
+++ ofbiz/trunk/applications/datamodel/entitydef/product-entitymodel.xml Sat
Jun 18 12:08:06 2016
@@ -4225,6 +4225,9 @@ under the License.
<field name="shipmentCustomMethodId" type="id"></field>
<field name="shipmentGatewayConfigId" type="id"></field>
<field name="sequenceNumber" type="numeric"></field>
+ <field name="allowancePercent" type="fixed-point"></field>
+ <field name="minimumPrice" type="currency-amount"></field>
+
<prim-key field="productStoreShipMethId"/>
<relation type="one-nofk" rel-entity-name="Party">
<key-map field-name="companyPartyId" rel-field-name="partyId"/>
Modified:
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java?rev=1748969&r1=1748968&r2=1748969&view=diff
==============================================================================
---
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java
(original)
+++
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java
Sat Jun 18 12:08:06 2016
@@ -24,9 +24,13 @@ import java.util.List;
import java.util.Map;
import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.util.EntityQuery;
import org.ofbiz.order.shoppingcart.ShoppingCart;
+import org.ofbiz.order.shoppingcart.ShoppingCartItem;
import org.ofbiz.product.store.ProductStoreWorker;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ServiceUtil;
@@ -71,8 +75,21 @@ public class ShippingEstimateWrapper {
this.partyId = cart.getPartyId();
this.supplierPartyId = cart.getSupplierPartyId(shipGroup);
+ BigDecimal totalAllowance = BigDecimal.ZERO;
+ if (UtilValidate.isNotEmpty(cart.getShipGroupItems(shipGroup))) {
+ try {
+ for (ShoppingCartItem item :
cart.getShipGroupItems(shipGroup).keySet()) {
+ GenericValue allowanceProductPrice =
EntityQuery.use(delegator).from("ProductPrice").where("productPriceTypeId",
"SHIPPING_ALLOWANCE", "productId",
item.getProductId()).filterByDate().queryFirst();
+ if (UtilValidate.isNotEmpty(allowanceProductPrice) &&
UtilValidate.isNotEmpty(allowanceProductPrice.get("price"))) {
+ totalAllowance =
totalAllowance.add(allowanceProductPrice.getBigDecimal("price")).multiply(item.getQuantity());
+ }
+ }
+ } catch (GenericEntityException gee) {
+ Debug.logError(gee.getMessage(), module);
+ }
+ }
this.loadShippingMethods();
- this.loadEstimates();
+ this.loadEstimates(totalAllowance);
}
protected void loadShippingMethods() {
@@ -84,7 +101,7 @@ public class ShippingEstimateWrapper {
}
}
- protected void loadEstimates() {
+ protected void loadEstimates(BigDecimal totalAllowance) {
this.shippingEstimates = new HashMap<GenericValue, BigDecimal>();
if (shippingMethods != null) {
for (GenericValue shipMethod : shippingMethods) {
@@ -96,7 +113,7 @@ public class ShippingEstimateWrapper {
Map<String, Object> estimateMap =
ShippingEvents.getShipGroupEstimate(dispatcher, delegator, "SALES_ORDER",
shippingMethodTypeId, carrierPartyId,
carrierRoleTypeId, shippingCmId, productStoreId,
- supplierPartyId, shippableItemInfo, shippableWeight,
shippableQuantity, shippableTotal, partyId, productStoreShipMethId);
+ supplierPartyId, shippableItemInfo, shippableWeight,
shippableQuantity, shippableTotal, partyId, productStoreShipMethId,
totalAllowance);
if (!ServiceUtil.isError(estimateMap)) {
BigDecimal shippingTotal = (BigDecimal)
estimateMap.get("shippingTotal");
Modified:
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEvents.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEvents.java?rev=1748969&r1=1748968&r2=1748969&view=diff
==============================================================================
---
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEvents.java
(original)
+++
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEvents.java
Sat Jun 18 12:08:06 2016
@@ -146,6 +146,16 @@ public class ShippingEvents {
String shipmentMethodTypeId, String carrierPartyId, String
carrierRoleTypeId, String shippingContactMechId,
String productStoreId, String supplierPartyId, List<Map<String,
Object>> itemInfo, BigDecimal shippableWeight, BigDecimal shippableQuantity,
BigDecimal shippableTotal, String partyId, String
productStoreShipMethId) {
+ return getShipGroupEstimate(dispatcher, delegator, orderTypeId,
+ shipmentMethodTypeId, carrierPartyId, carrierRoleTypeId,
shippingContactMechId,
+ productStoreId, supplierPartyId, itemInfo, shippableWeight,
shippableQuantity,
+ shippableTotal, partyId, productStoreShipMethId,
BigDecimal.ZERO);
+ }
+
+ public static Map<String, Object> getShipGroupEstimate(LocalDispatcher
dispatcher, Delegator delegator, String orderTypeId,
+ String shipmentMethodTypeId, String carrierPartyId, String
carrierRoleTypeId, String shippingContactMechId,
+ String productStoreId, String supplierPartyId, List<Map<String,
Object>> itemInfo, BigDecimal shippableWeight, BigDecimal shippableQuantity,
+ BigDecimal shippableTotal, String partyId, String
productStoreShipMethId, BigDecimal totalAllowance) {
String standardMessage = "A problem occurred calculating shipping.
Fees will be calculated offline.";
List<String> errorMessageList = new LinkedList<String>();
@@ -248,6 +258,21 @@ public class ShippingEvents {
return ServiceUtil.returnError(standardMessage);
}
+ // Calculate the allowance price(Already included in Product's
default/list price)
+ // using shippingAllowance percent and deduct it from Actual Shipping
Cost.
+ if (BigDecimal.ZERO.compareTo(shippingTotal) < 0 &&
BigDecimal.ZERO.compareTo(totalAllowance) < 0) {
+ BigDecimal shippingAllowancePercent =
storeShipMethod.getBigDecimal("allowancePercent") != null ?
storeShipMethod.getBigDecimal("allowancePercent") : BigDecimal.ZERO;
+ totalAllowance =
totalAllowance.multiply(shippingAllowancePercent.divide(BigDecimal.valueOf(100)));
+ shippingTotal = shippingTotal.subtract(totalAllowance);
+ }
+
+ // Check if minimum price is set for any Shipping Option, if yes,
+ // compare it with total shipping and use greater of the two.
+ BigDecimal minimumPrice =
storeShipMethod.getBigDecimal("minimumPrice");
+ if (UtilValidate.isNotEmpty(minimumPrice) &&
shippingTotal.compareTo(minimumPrice) < 0){
+ shippingTotal = minimumPrice;
+ }
+
// return the totals
Map<String, Object> responseResult = ServiceUtil.returnSuccess();
responseResult.put("shippingTotal", shippingTotal);
Modified: ofbiz/trunk/applications/product/data/ProductTypeData.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/data/ProductTypeData.xml?rev=1748969&r1=1748968&r2=1748969&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/data/ProductTypeData.xml (original)
+++ ofbiz/trunk/applications/product/data/ProductTypeData.xml Sat Jun 18
12:08:06 2016
@@ -466,6 +466,7 @@ under the License.
<ProductPriceType description="Special Promo Price"
productPriceTypeId="SPECIAL_PROMO_PRICE"/>
<ProductPriceType description="Box Price" productPriceTypeId="BOX_PRICE"/>
<ProductPriceType description="Minimum Order Price"
productPriceTypeId="MINIMUM_ORDER_PRICE"/>
+ <ProductPriceType description="Shipping Allowance Price"
productPriceTypeId="SHIPPING_ALLOWANCE"/>
<ProductPricePurpose description="Purchase/Initial"
productPricePurposeId="PURCHASE"/>
<ProductPricePurpose description="Recurring Charge"
productPricePurposeId="RECURRING_CHARGE"/>