Skip to content

Commit

Permalink
fix: handle undefined surcharges
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Dobbertin <[email protected]>
  • Loading branch information
aldeed committed Feb 20, 2019
1 parent d45495d commit 5afc5a8
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function startup(context) {
if (emittedBy === EMITTED_BY_NAME) return; // short circuit infinite loops
Logger.debug("Handling afterCartUpdate: surcharges");

const { shipping } = cart;
const { surcharges, shipping } = cart;
const cartSurcharges = [];

// Merge surcharges from each shipping group
Expand All @@ -41,7 +41,7 @@ export default function startup(context) {
// To avoid infinite looping among various `afterCartUpdate` handlers that also
// update cart and emit a subsequent `afterCartUpdate`, we need to be sure we
// do not do the update or emit the event unless we truly need to update something.
const previousSurcharges = cart.surcharges.map((appliedSurcharge) => ({ ...appliedSurcharge, _id: null }));
const previousSurcharges = (surcharges || []).map((appliedSurcharge) => ({ ...appliedSurcharge, _id: null }));
const nextSurcharges = cartSurcharges.map((appliedSurcharge) => ({ ...appliedSurcharge, _id: null }));
if (isEqual(previousSurcharges, nextSurcharges)) return;

Expand Down

0 comments on commit 5afc5a8

Please sign in to comment.