From 978363e21611da8a2d965e050b18c676635661ce Mon Sep 17 00:00:00 2001 From: newsiberian Date: Tue, 3 May 2016 17:46:48 +0600 Subject: [PATCH] - added checks for `this.shipping[0].shipmentMethod` is defined to `cartTransform`; --- .../common/collections/collections.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/reaction-collections/common/collections/collections.js b/packages/reaction-collections/common/collections/collections.js index edad2bac39a..710da17da7a 100644 --- a/packages/reaction-collections/common/collections/collections.js +++ b/packages/reaction-collections/common/collections/collections.js @@ -46,7 +46,12 @@ ReactionCore.Helpers.cartTransform = { }, cartShipping: function () { // loop through the cart.shipping, sum shipments. - return parseFloat(getSummary(this.shipping, ["shipmentMethod", "rate"])); + // shipmentMethod could be undefined if we resets workflow from more higher + // stage by adding new item to cart for example + if (typeof this.shipping[0].shipmentMethod === "object") { + return parseFloat(getSummary(this.shipping, ["shipmentMethod", "rate"])); + } + return 0; }, cartSubTotal: function () { return getSummary(this.items, ["quantity"], ["variants", "price"]). @@ -62,7 +67,10 @@ ReactionCore.Helpers.cartTransform = { cartTotal: function () { let subTotal = getSummary(this.items, ["quantity"], ["variants", "price"]); // loop through the cart.shipping, sum shipments. - let shippingTotal = getSummary(this.shipping, ["shipmentMethod", "rate"]); + let shippingTotal = 0; + if (typeof this.shipping[0].shipmentMethod === "object") { + shippingTotal = getSummary(this.shipping, ["shipmentMethod", "rate"]); + } shippingTotal = parseFloat(shippingTotal); // TODO: includes taxes? if (typeof shippingTotal === "number" && shippingTotal > 0) {