In shopping cart and summary, Discount is calculated as Sum of Order Adjustments. Patch from Brajesh Patel

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@676589 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Vikas Mayur
2008-07-14 13:52:20 +00:00
parent 057a87de89
commit b2a40a0be5
4 changed files with 31 additions and 23 deletions
@@ -377,7 +377,7 @@ function addPromoCode() {
} else if (data._ERROR_MESSAGE_ != undefined) {
$('cartFormServerError').update(data._ERROR_MESSAGE_);
} else {
$('cartDiscountValue').update(data.displayDiscountTotalCurrencyFormatted);
$('cartDiscountValue').update(data.displayOrderAdjustmentsTotalCurrencyFormatted);
$('cartSubTotal').update(data.subTotalCurrencyFormatted);
$('cartTotalShipping').update(data.totalShippingCurrencyFormatted);
$('cartTotalSalesTax').update(data.totalSalesTaxCurrencyFormatted);
@@ -387,7 +387,7 @@ function addPromoCode() {
$('completedCartTotalShipping').update(data.totalShippingCurrencyFormatted);
$('completedCartTotalSalesTax').update(data.totalSalesTaxCurrencyFormatted);
$('completedCartDisplayGrandTotal').update(data.displayGrandTotalCurrencyFormatted);
$('completedCartDiscount').update(data.displayDiscountTotalCurrencyFormatted);
$('completedCartDiscount').update(data.displayOrderAdjustmentsTotalCurrencyFormatted);
if (data.displayDiscountTotal < 0) {
$('completedCartDiscountRow').show();
} else {
@@ -458,7 +458,7 @@ function updateCartData(elementId, formValues, itemQty, itemIndex) {
} else {
// Used for edit cart
$('cartSubTotal').update(data.subTotalCurrencyFormatted);
$('cartDiscountValue').update(data.displayDiscountTotalCurrencyFormatted);
$('cartDiscountValue').update(data.displayOrderAdjustmentsTotalCurrencyFormatted);
$('cartTotalShipping').update(data.totalShippingCurrencyFormatted);
$('cartTotalSalesTax').update(data.totalSalesTaxCurrencyFormatted);
$('cartDisplayGrandTotal').update(data.displayGrandTotalCurrencyFormatted);
@@ -467,7 +467,7 @@ function updateCartData(elementId, formValues, itemQty, itemIndex) {
$('completedCartTotalShipping').update(data.totalShippingCurrencyFormatted);
$('completedCartTotalSalesTax').update(data.totalSalesTaxCurrencyFormatted);
$('completedCartDisplayGrandTotal').update(data.displayGrandTotalCurrencyFormatted);
$('completedCartDiscount').update(data.displayDiscountTotalCurrencyFormatted);
$('completedCartDiscount').update(data.displayOrderAdjustmentsTotalCurrencyFormatted);
if (elementId != undefined && $(elementId).value != "") {
if (itemQty == 0) {
var cartItemRowId = elementId.sub('qty_','cartItemRow_');
@@ -58,10 +58,10 @@ under the License.
<tr id="cartItemDisplayRow_${cartLineIndex}">
<td align="left"><div><img src="<@ofbizContentUrl>${requestAttributes.contentPathPrefix?if_exists}${smallImageUrl}</@ofbizContentUrl>" align="center" height="20" hspace="0" vspace="0" width="20"></div></td>
<td align="left"><div>${cartLine.getName()?if_exists}</div>
<td align="center"><div>@${cartLine.getDisplayPrice()}</div></td>
<td align="center"><div>${cartLine.getDisplayPrice()}</div></td>
<td align="center"><div><span id="completedCartItemQty_${cartLineIndex}">${cartLine.getQuantity()?string.number}</span></div></td>
<td align="center"><div><span id="completedCartItemAdjustment_${cartLineIndex}">${cartLine.getOtherAdjustments()?string.number}</span></div></td>
<td align="right"><div id="completedCartItemSubTotal_${cartLineIndex}"><@ofbizCurrency amount=cartLine.getDisplayItemSubTotalNoAdj() isoCode=shoppingCart.getCurrency()/></div></td>
<td align="center"><div><span id="completedCartItemAdjustment_${cartLineIndex}"><@ofbizCurrency amount=cartLine.getOtherAdjustments() isoCode=shoppingCart.getCurrency()/></span></div></td>
<td align="right"><div id="completedCartItemSubTotal_${cartLineIndex}"><@ofbizCurrency amount=cartLine.getDisplayItemSubTotal() isoCode=shoppingCart.getCurrency()/></div></td>
</tr>
<tr><td colspan="6"><hr class="sepbar"/></td></tr>
<#assign itemCount = itemCount + 1>
@@ -69,14 +69,21 @@ under the License.
<tr id="completedCartSubtotalRow">
<td colspan="4"></td>
<td><div align="right"><b>${uiLabelMap.CommonSubtotal}:</b></div></td>
<#assign initializedSubTotal = shoppingCart.getDisplaySubTotal() - shoppingCart.getProductPromoTotal()>
<td><div id="completedCartSubTotal" align="right"><@ofbizCurrency amount=initializedSubTotal isoCode=shoppingCart.getCurrency()/></div></td>
<td><div id="completedCartSubTotal" align="right"><@ofbizCurrency amount=shoppingCart.getSubTotal() isoCode=shoppingCart.getCurrency()/></div></td>
</tr>
<#assign orderAdjustmentsTotal = 0>
<#list shoppingCart.getAdjustments() as cartAdjustment>
<#assign orderAdjustmentsTotal = orderAdjustmentsTotal + Static["org.ofbiz.order.order.OrderReadHelper"].calcOrderAdjustment(cartAdjustment, shoppingCart.getSubTotal())>
</#list>
<tr id="completedCartDiscountRow">
<input type="hidden" value="<b>${shoppingCart.getProductPromoTotal()}</b>" id="initializedCompletedCartDiscount"/>
<input type="hidden" value="${orderAdjustmentsTotal}" id="initializedCompletedCartDiscount"/>
<td colspan="4"></td>
<td><div align="right"><b>${uiLabelMap.ProductDiscount}:</b></div></td>
<td><div id="completedCartDiscount" align="right"><@ofbizCurrency amount=shoppingCart.getProductPromoTotal() isoCode=shoppingCart.getCurrency()/></div></td>
<td>
<div id="completedCartDiscount" align="right">
<@ofbizCurrency amount=orderAdjustmentsTotal isoCode=shoppingCart.getCurrency()/>
</div>
</td>
</tr>
<tr>
<td colspan="4"></td>
@@ -150,7 +157,7 @@ under the License.
</td>
<td align="left"><div>${cartLine.getName()?if_exists}</div></td>
<td align="center"><div id="itemUnitPrice_${cartLineIndex}">
<@ofbizCurrency amount=cartLine.getDisplayPrice() isoCode=shoppingCart.getCurrency() rounding=2/></div>
<@ofbizCurrency amount=cartLine.getDisplayPrice() isoCode=shoppingCart.getCurrency()/></div>
</td>
<td align="center">
<#if cartLine.getIsPromo()>
@@ -172,11 +179,7 @@ under the License.
<#else>
<td nowrap align="center"><div class="tabletext"><@ofbizCurrency amount=cartLine.getOtherAdjustments() isoCode=shoppingCart.getCurrency()/></div></td>
</#if>
<#if cartLine.getIsPromo()>
<td align="center">FREE</td>
<#else>
<td align="center"><div id="displayItem_${cartLineIndex}"><@ofbizCurrency amount=cartLine.getDisplayItemSubTotalNoAdj() isoCode=shoppingCart.getCurrency()/></div></td>
</#if>
<td align="center"><div id="displayItem_${cartLineIndex}"><@ofbizCurrency amount=cartLine.getDisplayItemSubTotal() isoCode=shoppingCart.getCurrency()/></div></td>
<#if !cartLine.getIsPromo()>
<td align="right"><a href="javascript:void(0);"><img id="remove_${cartLineIndex?if_exists}" src="<@ofbizContentUrl>/ecommerce/images/remove.png</@ofbizContentUrl>" border="0" height="30" hspace="0" vspace="0" width="40"></a></td>
</#if>
@@ -188,8 +191,7 @@ under the License.
<tr>
<td colspan="4"></td>
<td><div align="right"><b>${uiLabelMap.CommonSubtotal}:</b></div></td>
<#assign initializedSubTotal = shoppingCart.getDisplaySubTotal() - shoppingCart.getProductPromoTotal()>
<td><div id="cartSubTotal" align="center"><@ofbizCurrency amount=initializedSubTotal isoCode=shoppingCart.getCurrency()/></div></td>
<td><div id="cartSubTotal" align="center"><@ofbizCurrency amount=shoppingCart.getSubTotal() isoCode=shoppingCart.getCurrency()/></div></td>
</tr>
<tr>
<td colspan="4">
@@ -199,7 +201,13 @@ under the License.
</td>
<td><div id="cartDiscount" align="right"><b>${uiLabelMap.ProductDiscount}:</b></div></td>
<td>
<div id="cartDiscountValue" align="center"><@ofbizCurrency amount=shoppingCart.getProductPromoTotal() isoCode=shoppingCart.getCurrency()/></div>
<div id="cartDiscountValue" align="center">
<#assign orderAdjustmentsTotal = 0>
<#list shoppingCart.getAdjustments() as cartAdjustment>
<#assign orderAdjustmentsTotal = orderAdjustmentsTotal + Static["org.ofbiz.order.order.OrderReadHelper"].calcOrderAdjustment(cartAdjustment, shoppingCart.getSubTotal())>
</#list>
<@ofbizCurrency amount=orderAdjustmentsTotal isoCode=shoppingCart.getCurrency()/>
</div>
</td>
</tr>
<tr>
@@ -132,7 +132,7 @@ under the License.
<attribute name="displayGrandTotal" type="Double" mode="OUT" optional="true"/>
<attribute name="displayGrandTotalCurrencyFormatted" type="String" mode="OUT" optional="true"/>
<attribute name="cartItemData" type="Map" mode="OUT"/>
<attribute name="displayDiscountTotalCurrencyFormatted" type="String" mode="OUT" optional="true"/>
<attribute name="displayOrderAdjustmentsTotalCurrencyFormatted" type="String" mode="OUT" optional="true"/>
</service>
<service name="getShoppingCartItemIndex" engine="java" auth="false"
@@ -850,8 +850,8 @@ public class ShoppingCartServices {
result.put("totalSalesTaxCurrencyFormatted",org.ofbiz.base.util.UtilFormatOut.formatCurrency(shoppingCart.getTotalSalesTax(),isoCode,locale));
result.put("displayGrandTotal",new Double(shoppingCart.getDisplayGrandTotal()));
result.put("displayGrandTotalCurrencyFormatted",org.ofbiz.base.util.UtilFormatOut.formatCurrency(shoppingCart.getDisplayGrandTotal(),isoCode,locale));
result.put("displayDiscountTotalCurrencyFormatted",org.ofbiz.base.util.UtilFormatOut.formatCurrency(shoppingCart.getProductPromoTotal(),isoCode,locale));
double orderAdjustmentsTotal = OrderReadHelper.calcOrderAdjustments(OrderReadHelper.getOrderHeaderAdjustments(shoppingCart.getAdjustments(), null), BigDecimal.valueOf(shoppingCart.getSubTotal()), true, true, true).doubleValue();
result.put("displayOrderAdjustmentsTotalCurrencyFormatted", org.ofbiz.base.util.UtilFormatOut.formatCurrency(orderAdjustmentsTotal, isoCode, locale));
Iterator i = shoppingCart.iterator();
Map cartItemData = FastMap.newInstance();
while (i.hasNext()) {