Skip to content

Commit

Permalink
COM-3667 : Fix to calculate the proper subtotal amount on apple pay (#…
Browse files Browse the repository at this point in the history
…336)

The fix is to get the correct attribute(productDiscounts.impact) on the json to calculate the subtotal amount.
  • Loading branch information
kibo-raghu authored May 11, 2021
1 parent b051b97 commit 3271919
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion scripts/modules/applepay.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,23 @@ function($, Hypr, Api, hyprlivecontext, _, Backbone, CartModels, CheckoutModels,
var self = this;
var totalAmount = self.getTotal();
var newLineItems = [];
var itemLevelProductDiscountTotal = 0;

if(self.MultishipEnabled){
itemLevelProductDiscountTotal = self.orderModel.get('itemLevelProductDiscountTotal') || 0;
} else{
var items = self.orderModel.get('items');
items.forEach(function(item){
if(Array.isArray(item.productDiscounts) && item.productDiscounts.length){
var productDiscounts = item.productDiscounts;
productDiscounts.forEach(function(productDiscount){
itemLevelProductDiscountTotal = itemLevelProductDiscountTotal + productDiscount.impact;
});
}
});
}
//casing for the subtotal value varies depending on context apparently... eye roll emoji
var subtotalAmount = (self.orderModel.get('subTotal') || self.orderModel.get('subtotal')) - (self.orderModel.get('itemLevelProductDiscountTotal') || 0);
var subtotalAmount = (self.orderModel.get('subTotal') || self.orderModel.get('subtotal')) - itemLevelProductDiscountTotal;
if (totalAmount != subtotalAmount){
newLineItems.push({
"label": "Subtotal",
Expand Down

0 comments on commit 3271919

Please sign in to comment.