Skip to content

Commit

Permalink
Merge pull request #1 from thoughtindustries/issue-3179
Browse files Browse the repository at this point in the history
Issue 3179
  • Loading branch information
mdeltito authored Mar 19, 2019
2 parents 7f450bb + ccfdf10 commit 4067a30
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ function totalDueNow(orderItem) {
return orderItem.total;
} else {
var quantity = orderItem.quantity || 0,
total = orderItem.priceInCents;
total = orderItem.priceInCents;

if (orderItem.variation) {
total += orderItem.variation.priceInCents || 0;
}

if (orderItem.coupon) {
if (orderItem.purchasableType === 'bundle' && quantity > 1) {
total = total * quantity;
quantity = 1;
}
total = Math.round(discountable(total, orderItem.coupon.percentOff, orderItem.coupon.amountOffInCents));
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "couponable",
"description": "Helper functions for dealing with coupons.",
"version": "6.0.0",
"version": "6.0.1",
"author": "Chris McC",
"license": "MIT",
"repository": {
Expand Down
9 changes: 9 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ describe('totalDueNow', function() {
priceInCents: 2
}), 1);
});

it('handles coupons for bundles correctly', function() {
assert.equal(totalDueNow({
quantity: 10,
coupon: {amountOffInCents: 5},
priceInCents: 10,
purchasableType: 'bundle'
}), 95)
});
});

describe('totalRecurring', function() {
Expand Down

0 comments on commit 4067a30

Please sign in to comment.