From 5afc5a8fcbb231a07d38782875ec633b2e5895a7 Mon Sep 17 00:00:00 2001 From: Eric Dobbertin Date: Tue, 19 Feb 2019 18:50:35 -0600 Subject: [PATCH] fix: handle undefined surcharges Signed-off-by: Eric Dobbertin --- .../plugins/included/surcharges/server/no-meteor/startup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imports/plugins/included/surcharges/server/no-meteor/startup.js b/imports/plugins/included/surcharges/server/no-meteor/startup.js index 8440750848f..8271c75a4f6 100644 --- a/imports/plugins/included/surcharges/server/no-meteor/startup.js +++ b/imports/plugins/included/surcharges/server/no-meteor/startup.js @@ -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 @@ -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;