From ede44c856bee486cb73f90a8b84e9d7d1a820c3c Mon Sep 17 00:00:00 2001
From: Mark Moffat <mark@Marks-MacBook-Pro-2.local>
Date: Fri, 3 Jan 2020 22:47:04 +1030
Subject: [PATCH] Free shipping when paymentGateway is set to instore

---
 lib/common.js                 | 2 +-
 lib/modules/shipping-basic.js | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/common.js b/lib/common.js
index 3adf6f8..31101f7 100755
--- a/lib/common.js
+++ b/lib/common.js
@@ -132,7 +132,7 @@ const updateTotalCart = (req, res) => {
     req.session.totalCartItems = Object.keys(req.session.cart).length;
 
     // Calculate shipping using the loaded module
-    const shippingCost = config.modules.loaded.shipping.calculateShipping(req.session.totalCartAmount);
+    const shippingCost = config.modules.loaded.shipping.calculateShipping(req.session.totalCartAmount, config);
     if(shippingCost > 0){
         req.session.totalCartShipping = parseInt(shippingCost);
         req.session.totalCartAmount = req.session.totalCartAmount + parseInt(shippingCost);
diff --git a/lib/modules/shipping-basic.js b/lib/modules/shipping-basic.js
index bcef94f..65a069a 100644
--- a/lib/modules/shipping-basic.js
+++ b/lib/modules/shipping-basic.js
@@ -1,7 +1,11 @@
 const shippingAmount = 10;
 const freeThreshold = 100;
 
-const calculateShipping = (amount) => {
+const calculateShipping = (amount, config) => {
+    // When set to instore shipping is not applicable.
+    if(config.paymentGateway === 'instore'){
+        return 0;
+    }
     if(amount >= freeThreshold){
         return 0;
     }