From 11302e22553a2889f9fc9d461be5c83ad63ab537 Mon Sep 17 00:00:00 2001 From: Mark Moffat Date: Sat, 4 Jan 2020 17:40:58 +1030 Subject: [PATCH] Improvements to the shipping module & cart updates --- lib/common.js | 16 +++++----- lib/modules/shipping-basic.js | 35 ++++++++++++++++++--- public/javascripts/expressCart.js | 20 ++++++------ public/javascripts/expressCart.min.js | 2 +- routes/index.js | 14 ++++++--- views/layouts/layout.hbs | 2 +- views/themes/Cloth/cart.hbs | 6 ++-- views/themes/Cloth/checkout-cart.hbs | 2 +- views/themes/Cloth/checkout-information.hbs | 2 +- views/themes/Cloth/checkout-payment.hbs | 4 +-- views/themes/Cloth/checkout-shipping.hbs | 8 ++--- 11 files changed, 71 insertions(+), 40 deletions(-) diff --git a/lib/common.js b/lib/common.js index 31101f7..4972300 100755 --- a/lib/common.js +++ b/lib/common.js @@ -131,15 +131,15 @@ const updateTotalCart = (req, res) => { // Update the total items in cart for the badge req.session.totalCartItems = Object.keys(req.session.cart).length; + // Net cart amount + const netCartAmount = req.session.totalCartAmount - req.session.totalCartShipping || 0; + // Calculate shipping using the loaded module - 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); - req.session.shippingCostApplied = true; - }else{ - req.session.shippingCostApplied = false; - } + config.modules.loaded.shipping.calculateShipping( + netCartAmount, + config, + req + ); }; const emptyCart = async (req, res, type, customMessage) => { diff --git a/lib/modules/shipping-basic.js b/lib/modules/shipping-basic.js index 65a069a..7858e8c 100644 --- a/lib/modules/shipping-basic.js +++ b/lib/modules/shipping-basic.js @@ -1,15 +1,40 @@ -const shippingAmount = 10; +const domesticShippingAmount = 10; +const internationalShippingAmount = 25; const freeThreshold = 100; +const shippingFromCountry = 'Australia'; -const calculateShipping = (amount, config) => { +const calculateShipping = (amount, config, req) => { // When set to instore shipping is not applicable. if(config.paymentGateway === 'instore'){ - return 0; + // Update message and amount + req.session.shippingMessage = 'Instore pickup'; + req.session.totalCartShipping = 0; + return; } + if(amount >= freeThreshold){ - return 0; + req.session.shippingMessage = 'FREE shipping'; + req.session.totalCartShipping = 0; + return; } - return shippingAmount; + + // If there is no country set, we estimate shipping + if(!req.session.customerCountry){ + req.session.shippingMessage = 'Estimated shipping'; + req.session.totalCartShipping = domesticShippingAmount; + return; + } + + // Check for international + if(req.session.customerCountry.toLowerCase() !== shippingFromCountry.toLowerCase()){ + req.session.shippingMessage = 'International shipping'; + req.session.totalCartShipping = internationalShippingAmount; + return; + } + + // Domestic shipping + req.session.shippingMessage = 'Domestic shipping'; + req.session.totalCartShipping = domesticShippingAmount; }; module.exports = { diff --git a/public/javascripts/expressCart.js b/public/javascripts/expressCart.js index 47d00f3..e9ebe02 100644 --- a/public/javascripts/expressCart.js +++ b/public/javascripts/expressCart.js @@ -486,9 +486,9 @@ function updateCartDiv(){ // Work out the shipping var shippingTotalAmt = numeral(session.totalCartShipping).format('0.00'); - var shippingTotal = `${result.currencySymbol}${shippingTotalAmt}`; - if(shippingTotalAmt === 0){ - shippingTotal = 'FREE'; + var shippingTotal = `${session.shippingMessage} :${result.currencySymbol}${shippingTotalAmt}`; + if(session.totalCartShipping === 0){ + shippingTotal = `${session.shippingMessage}`; } // If the cart has contents @@ -550,10 +550,10 @@ function updateCartDiv(){ `; }); - $('#cartBodyWrapper').html(productHtml); + $('.cartBodyWrapper').html(productHtml); $('#cart-count').text(session.totalCartItems); }else{ - $('#cartBodyWrapper').html(''); + $('.cartBodyWrapper').html(''); } // Set the totals section @@ -561,7 +561,7 @@ function updateCartDiv(){
- Shipping: ${shippingTotal} + ${shippingTotal}
Total: @@ -579,11 +579,11 @@ function updateCartDiv(){ // Set depending on cart contents if(cart){ - $('#cartTotalsWrapper').html(cartTotalsHtml); - $('#cart-buttons').removeClass('d-none'); + $('.cartTotalsWrapper').html(cartTotalsHtml); + $('.cart-buttons').removeClass('d-none'); }else{ - $('#cartTotalsWrapper').html(cartTotalsEmptyHtml); - $('#cart-buttons').addClass('d-none'); + $('.cartTotalsWrapper').html(cartTotalsEmptyHtml); + $('.cart-buttons').addClass('d-none'); } }) .fail(function(result){ diff --git a/public/javascripts/expressCart.min.js b/public/javascripts/expressCart.min.js index 7722eb6..9ec7361 100644 --- a/public/javascripts/expressCart.min.js +++ b/public/javascripts/expressCart.min.js @@ -1 +1 @@ -function deleteFromCart(t){$.ajax({method:"POST",url:"/product/removefromcart",data:{productId:t.attr("data-id")}}).done(function(t){showNotification(t.message,"success"),updateCartDiv()}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}function cartUpdate(t){$(t).val()>0?""!==$(t).val()&&updateCart(t):$(t).val(1)}function updateCart(t){$.ajax({method:"POST",url:"/product/updatecart",data:{productId:t.attr("data-id"),quantity:t.val()}}).done(function(t){updateCartDiv()}).fail(function(t){showNotification(t.responseJSON.message,"danger",!0)})}function getSelectedOptions(){var t={};return $(".product-opt").each(function(){var a=$(this).val().trim(),e=$(this).attr("data-label"),n=$(this).attr("name"),o=$(this).attr("type");o||(t[n]={label:e,name:n,value:a}),"radio"===o&&(t[n]={label:e,name:n,value:$('input[name="'+n+'"]:checked').val()}),"checkbox"===o&&(t[n]={label:e,name:n,value:$('input[name="'+$(this).attr("name")+'"]').is(":checked")})}),t}function updateCartDiv(){$.ajax({method:"GET",url:"/checkout/cartdata"}).done(function(t){var a=t.cart,e=t.session,n="",o=numeral(e.totalCartAmount).format("0.00"),i=numeral(e.totalCartShipping).format("0.00"),r=`${t.currencySymbol}${i}`;0===i&&(r='FREE'),a?($("#cart-empty").empty(),Object.keys(a).forEach(function(e){var o=a[e],i=numeral(o.totalItemPrice).format("0.00"),r="",s=1;Object.keys(o.options).forEach(function(t){var a=o.options[t];s===Object.keys(o.options).length?r+=`${upperFirst(a.name)}: ${a.value}`:r+=`${upperFirst(a.name)}: ${a.value} / `,s++});var c=`${o.title} product image`;o.productImage&&(c=`${o.title} product image`),n+=`\n
\n
\n ${c}\n
\n
\n
\n \n
\n ${r}\n
\n
\n
\n
\n \n
\n \n
\n \n
\n
\n
\n
\n \n
\n
\n
\n
\n ${t.currencySymbol}${i}\n
\n
`}),$("#cartBodyWrapper").html(n),$("#cart-count").text(e.totalCartItems)):$("#cartBodyWrapper").html("");var s=`\n
\n
\n
\n Shipping: ${r}\n
\n
\n Total:\n ${t.currencySymbol}${o}\n
\n
\n
`;a?($("#cartTotalsWrapper").html(s),$("#cart-buttons").removeClass("d-none")):($("#cartTotalsWrapper").html('\n
\n
\n Cart empty\n
\n
'),$("#cart-buttons").addClass("d-none"))}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}function upperFirst(t){return t.replace(/^\w/,t=>t.toUpperCase())}$(document).ready(function(){if($(window).width()<768&&($(".menu-side").on("click",function(t){t.preventDefault(),$('.menu-side li:not(".active")').slideToggle()}),$('.menu-side li:not(".active")').hide(),$(".menu-side>.active").html(''),$(".menu-side>.active").addClass("menu-side-mobile"),0===$("#navbar ul li").length&&$("#navbar").hide(),$("#offcanvasClose").hide()),$("#userSetupForm").validator().on("submit",function(t){t.isDefaultPrevented()||(t.preventDefault(),$.ajax({method:"POST",url:"/admin/setup_action",data:{usersName:$("#usersName").val(),userEmail:$("#userEmail").val(),userPassword:$("#userPassword").val()}}).done(function(t){showNotification(t.message,"success",!1,"/admin/login")}).fail(function(t){showNotification(t.responseJSON.message,"danger")}))}),$(document).on("click",".menu-btn",function(t){t.preventDefault(),$("body").addClass("pushy-open-right")}),$("table").each(function(){$(this).addClass("table table-hover")}),$("#productTags").length&&$("#productTags").tokenfield(),$(document).on("click",".dashboard_list",function(t){window.document.location=$(this).attr("href")}).hover(function(){$(this).toggleClass("hover")}),$(document).on("click",".btn-qty-minus",function(t){t.preventDefault();var a=$(t.target).parent().parent().find(".cart-product-quantity");$(a).val(parseInt(a.val())-1),cartUpdate(a)}),$(document).on("click",".btn-qty-add",function(t){t.preventDefault();var a=$(t.target).parent().parent().find(".cart-product-quantity");$(a).val(parseInt(a.val())+1),cartUpdate(a)}),$(document).on("click",".btn-delete-from-cart",function(t){deleteFromCart($(t.target))}),$("#pager").length){var t=$("#pageNum").val(),a=$("#productsPerPage").val(),e=$("#totalProductCount").val(),n=$("#paginateUrl").val(),o=$("#searchTerm").val();""!==o&&(o+="/");var i="/"+n+"/"+o+"{{number}}",r=Math.ceil(e/a);parseInt(e)>parseInt(a)&&($("#pager").bootpag({total:r,page:t,maxVisible:5,href:i,wrapClass:"pagination",prevClass:"page-item previous",nextClass:"page-item next",activeClass:"page-item active"}),$("#pager a").each(function(){$(this).addClass("page-link")}))}if($("#customerLogout").on("click",function(t){$.ajax({method:"POST",url:"/customer/logout",data:{}}).done(function(t){location.reload()})}),$("#customerForgotten").validator().on("submit",function(t){t.isDefaultPrevented()||(t.preventDefault(),$.ajax({method:"POST",url:"/customer/forgotten_action",data:{email:$("#email").val()}}).done(function(t){showNotification(t.message,"success")}).fail(function(t){t.message?showNotification(t.responseJSON.message,"danger"):showNotification(t.responseText,"danger")}))}),$(document).on("click","#createAccountCheckbox",function(t){$("#newCustomerPassword").prop("required",$("#createAccountCheckbox").prop("checked"))}),$("#checkoutInformation").validator().on("click",function(t){if(t.preventDefault(),0===$("#shipping-form").validator("validate").has(".has-error").length){var a="/customer/save";$("#createAccountCheckbox").prop("checked")&&(a="/customer/create"),$.ajax({method:"POST",url:a,data:{email:$("#shipEmail").val(),firstName:$("#shipFirstname").val(),lastName:$("#shipLastname").val(),address1:$("#shipAddr1").val(),address2:$("#shipAddr2").val(),country:$("#shipCountry").val(),state:$("#shipState").val(),postcode:$("#shipPostcode").val(),phone:$("#shipPhoneNumber").val(),password:$("#newCustomerPassword").val(),orderComment:$("#orderComment").val()}}).done(function(){window.location="/checkout/shipping"}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}}),$("#loginForm").on("click",function(t){t.isDefaultPrevented()||(t.preventDefault(),$.ajax({method:"POST",url:"/admin/login_action",data:{email:$("#email").val(),password:$("#password").val()}}).done(function(t){window.location="/admin"}).fail(function(t){showNotification(t.responseJSON.message,"danger")})),t.preventDefault()}),$("#customerLogin").on("click",function(t){t.isDefaultPrevented()||(t.preventDefault(),$.ajax({method:"POST",url:"/customer/login_action",data:{loginEmail:$("#customerLoginEmail").val(),loginPassword:$("#customerLoginPassword").val()}}).done(function(t){var a=t.customer;$("#shipEmail").val(a.email),$("#shipFirstname").val(a.firstName),$("#shipLastname").val(a.lastName),$("#shipAddr1").val(a.address1),$("#shipAddr2").val(a.address2),$("#shipCountry").val(a.country),$("#shipState").val(a.state),$("#shipPostcode").val(a.postcode),$("#shipPhoneNumber").val(a.phone),location.reload()}).fail(function(t){showNotification(t.responseJSON.message,"danger")})),t.preventDefault()}),$(document).on("click",".image-next",function(t){var a=$(".thumbnail-image"),e=0,n=0;$(".thumbnail-image").each(function(){$("#product-title-image").attr("src")===$(this).attr("src")&&(n=e+1===a.length||e+1<0?0:e+1),e++}),$("#product-title-image").attr("src",$(a).eq(n).attr("src"))}),$(document).on("click",".image-prev",function(t){var a=$(".thumbnail-image"),e=0,n=0;$(".thumbnail-image").each(function(){$("#product-title-image").attr("src")===$(this).attr("src")&&(n=e-1===a.length||e-1<0?a.length-1:e-1),e++}),$("#product-title-image").attr("src",$(a).eq(n).attr("src"))}),$(document).on("click",".product-add-to-cart",function(t){var a=getSelectedOptions();parseInt($("#product_quantity").val())<0&&$("#product_quantity").val(0),$.ajax({method:"POST",url:"/product/addtocart",data:{productId:$("#productId").val(),productQuantity:$("#product_quantity").val(),productOptions:JSON.stringify(a),productComment:$("#product_comment").val()}}).done(function(t){showNotification(t.message,"success"),updateCartDiv()}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$(".cart-product-quantity").on("focusout",function(t){cartUpdate($(t.target))}),$(document).on("click",".pushy-link",function(t){$("body").removeClass("pushy-open-right")}),$(document).on("click",".add-to-cart",function(t){var a="/product/"+$(this).attr("data-id");$(this).attr("data-link")&&(a="/product/"+$(this).attr("data-link")),"true"===$(this).attr("data-has-options")?window.location=a:$.ajax({method:"POST",url:"/product/addtocart",data:{productId:$(this).attr("data-id")}}).done(function(t){showNotification(t.message,"success"),updateCartDiv()}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$(document).on("click","#empty-cart",function(t){$.ajax({method:"POST",url:"/product/emptycart"}).done(function(t){updateCartDiv(),showNotification(t.message,"success",!0)})}),$(".qty-btn-minus").on("click",function(){var t=parseInt($("#product_quantity").val())-1;$("#product_quantity").val(t>0?t:1)}),$(".qty-btn-plus").on("click",function(){$("#product_quantity").val(parseInt($("#product_quantity").val())+1)}),$(".thumbnail-image").on("click",function(){$("#product-title-image").attr("src",$(this).attr("src"))}),$(document).on("click","#btn_search_reset",function(t){window.location.replace("/")}),$(document).on("click","#btn_search",function(t){t.preventDefault(),""===$("#frm_search").val().trim()?showNotification("Please enter a search value","danger"):window.location.href="/search/"+$("#frm_search").val()}),""!==$("#input_notify_message").val()){var s=$("#input_notify_message").val(),c=$("#input_notify_messageType").val();$("#input_notify_message").val(""),$("#input_notify_messageType").val(""),showNotification(s,c||"danger",!1)}}); \ No newline at end of file +function deleteFromCart(t){$.ajax({method:"POST",url:"/product/removefromcart",data:{productId:t.attr("data-id")}}).done(function(t){showNotification(t.message,"success"),updateCartDiv()}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}function cartUpdate(t){$(t).val()>0?""!==$(t).val()&&updateCart(t):$(t).val(1)}function updateCart(t){$.ajax({method:"POST",url:"/product/updatecart",data:{productId:t.attr("data-id"),quantity:t.val()}}).done(function(t){updateCartDiv()}).fail(function(t){showNotification(t.responseJSON.message,"danger",!0)})}function getSelectedOptions(){var t={};return $(".product-opt").each(function(){var a=$(this).val().trim(),e=$(this).attr("data-label"),n=$(this).attr("name"),o=$(this).attr("type");o||(t[n]={label:e,name:n,value:a}),"radio"===o&&(t[n]={label:e,name:n,value:$('input[name="'+n+'"]:checked').val()}),"checkbox"===o&&(t[n]={label:e,name:n,value:$('input[name="'+$(this).attr("name")+'"]').is(":checked")})}),t}function updateCartDiv(){$.ajax({method:"GET",url:"/checkout/cartdata"}).done(function(t){var a=t.cart,e=t.session,n="",o=numeral(e.totalCartAmount).format("0.00"),i=numeral(e.totalCartShipping).format("0.00"),r=`${e.shippingMessage} :${t.currencySymbol}${i}`;0===e.totalCartShipping&&(r=`${e.shippingMessage}`),a?($("#cart-empty").empty(),Object.keys(a).forEach(function(e){var o=a[e],i=numeral(o.totalItemPrice).format("0.00"),r="",s=1;Object.keys(o.options).forEach(function(t){var a=o.options[t];s===Object.keys(o.options).length?r+=`${upperFirst(a.name)}: ${a.value}`:r+=`${upperFirst(a.name)}: ${a.value} / `,s++});var c=`${o.title} product image`;o.productImage&&(c=`${o.title} product image`),n+=`\n
\n
\n ${c}\n
\n
\n
\n \n
\n ${r}\n
\n
\n
\n
\n \n
\n \n
\n \n
\n
\n
\n
\n \n
\n
\n
\n
\n ${t.currencySymbol}${i}\n
\n
`}),$(".cartBodyWrapper").html(n),$("#cart-count").text(e.totalCartItems)):$(".cartBodyWrapper").html("");var s=`\n
\n
\n
\n ${r}\n
\n
\n Total:\n ${t.currencySymbol}${o}\n
\n
\n
`;a?($(".cartTotalsWrapper").html(s),$(".cart-buttons").removeClass("d-none")):($(".cartTotalsWrapper").html('\n
\n
\n Cart empty\n
\n
'),$(".cart-buttons").addClass("d-none"))}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}function upperFirst(t){return t.replace(/^\w/,t=>t.toUpperCase())}$(document).ready(function(){if($(window).width()<768&&($(".menu-side").on("click",function(t){t.preventDefault(),$('.menu-side li:not(".active")').slideToggle()}),$('.menu-side li:not(".active")').hide(),$(".menu-side>.active").html(''),$(".menu-side>.active").addClass("menu-side-mobile"),0===$("#navbar ul li").length&&$("#navbar").hide(),$("#offcanvasClose").hide()),$("#userSetupForm").validator().on("submit",function(t){t.isDefaultPrevented()||(t.preventDefault(),$.ajax({method:"POST",url:"/admin/setup_action",data:{usersName:$("#usersName").val(),userEmail:$("#userEmail").val(),userPassword:$("#userPassword").val()}}).done(function(t){showNotification(t.message,"success",!1,"/admin/login")}).fail(function(t){showNotification(t.responseJSON.message,"danger")}))}),$(document).on("click",".menu-btn",function(t){t.preventDefault(),$("body").addClass("pushy-open-right")}),$("table").each(function(){$(this).addClass("table table-hover")}),$("#productTags").length&&$("#productTags").tokenfield(),$(document).on("click",".dashboard_list",function(t){window.document.location=$(this).attr("href")}).hover(function(){$(this).toggleClass("hover")}),$(document).on("click",".btn-qty-minus",function(t){t.preventDefault();var a=$(t.target).parent().parent().find(".cart-product-quantity");$(a).val(parseInt(a.val())-1),cartUpdate(a)}),$(document).on("click",".btn-qty-add",function(t){t.preventDefault();var a=$(t.target).parent().parent().find(".cart-product-quantity");$(a).val(parseInt(a.val())+1),cartUpdate(a)}),$(document).on("click",".btn-delete-from-cart",function(t){deleteFromCart($(t.target))}),$("#pager").length){var t=$("#pageNum").val(),a=$("#productsPerPage").val(),e=$("#totalProductCount").val(),n=$("#paginateUrl").val(),o=$("#searchTerm").val();""!==o&&(o+="/");var i="/"+n+"/"+o+"{{number}}",r=Math.ceil(e/a);parseInt(e)>parseInt(a)&&($("#pager").bootpag({total:r,page:t,maxVisible:5,href:i,wrapClass:"pagination",prevClass:"page-item previous",nextClass:"page-item next",activeClass:"page-item active"}),$("#pager a").each(function(){$(this).addClass("page-link")}))}if($("#customerLogout").on("click",function(t){$.ajax({method:"POST",url:"/customer/logout",data:{}}).done(function(t){location.reload()})}),$("#customerForgotten").validator().on("submit",function(t){t.isDefaultPrevented()||(t.preventDefault(),$.ajax({method:"POST",url:"/customer/forgotten_action",data:{email:$("#email").val()}}).done(function(t){showNotification(t.message,"success")}).fail(function(t){t.message?showNotification(t.responseJSON.message,"danger"):showNotification(t.responseText,"danger")}))}),$(document).on("click","#createAccountCheckbox",function(t){$("#newCustomerPassword").prop("required",$("#createAccountCheckbox").prop("checked"))}),$("#checkoutInformation").validator().on("click",function(t){if(t.preventDefault(),0===$("#shipping-form").validator("validate").has(".has-error").length){var a="/customer/save";$("#createAccountCheckbox").prop("checked")&&(a="/customer/create"),$.ajax({method:"POST",url:a,data:{email:$("#shipEmail").val(),firstName:$("#shipFirstname").val(),lastName:$("#shipLastname").val(),address1:$("#shipAddr1").val(),address2:$("#shipAddr2").val(),country:$("#shipCountry").val(),state:$("#shipState").val(),postcode:$("#shipPostcode").val(),phone:$("#shipPhoneNumber").val(),password:$("#newCustomerPassword").val(),orderComment:$("#orderComment").val()}}).done(function(){window.location="/checkout/shipping"}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}}),$("#loginForm").on("click",function(t){t.isDefaultPrevented()||(t.preventDefault(),$.ajax({method:"POST",url:"/admin/login_action",data:{email:$("#email").val(),password:$("#password").val()}}).done(function(t){window.location="/admin"}).fail(function(t){showNotification(t.responseJSON.message,"danger")})),t.preventDefault()}),$("#customerLogin").on("click",function(t){t.isDefaultPrevented()||(t.preventDefault(),$.ajax({method:"POST",url:"/customer/login_action",data:{loginEmail:$("#customerLoginEmail").val(),loginPassword:$("#customerLoginPassword").val()}}).done(function(t){var a=t.customer;$("#shipEmail").val(a.email),$("#shipFirstname").val(a.firstName),$("#shipLastname").val(a.lastName),$("#shipAddr1").val(a.address1),$("#shipAddr2").val(a.address2),$("#shipCountry").val(a.country),$("#shipState").val(a.state),$("#shipPostcode").val(a.postcode),$("#shipPhoneNumber").val(a.phone),location.reload()}).fail(function(t){showNotification(t.responseJSON.message,"danger")})),t.preventDefault()}),$(document).on("click",".image-next",function(t){var a=$(".thumbnail-image"),e=0,n=0;$(".thumbnail-image").each(function(){$("#product-title-image").attr("src")===$(this).attr("src")&&(n=e+1===a.length||e+1<0?0:e+1),e++}),$("#product-title-image").attr("src",$(a).eq(n).attr("src"))}),$(document).on("click",".image-prev",function(t){var a=$(".thumbnail-image"),e=0,n=0;$(".thumbnail-image").each(function(){$("#product-title-image").attr("src")===$(this).attr("src")&&(n=e-1===a.length||e-1<0?a.length-1:e-1),e++}),$("#product-title-image").attr("src",$(a).eq(n).attr("src"))}),$(document).on("click",".product-add-to-cart",function(t){var a=getSelectedOptions();parseInt($("#product_quantity").val())<0&&$("#product_quantity").val(0),$.ajax({method:"POST",url:"/product/addtocart",data:{productId:$("#productId").val(),productQuantity:$("#product_quantity").val(),productOptions:JSON.stringify(a),productComment:$("#product_comment").val()}}).done(function(t){showNotification(t.message,"success"),updateCartDiv()}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$(".cart-product-quantity").on("focusout",function(t){cartUpdate($(t.target))}),$(document).on("click",".pushy-link",function(t){$("body").removeClass("pushy-open-right")}),$(document).on("click",".add-to-cart",function(t){var a="/product/"+$(this).attr("data-id");$(this).attr("data-link")&&(a="/product/"+$(this).attr("data-link")),"true"===$(this).attr("data-has-options")?window.location=a:$.ajax({method:"POST",url:"/product/addtocart",data:{productId:$(this).attr("data-id")}}).done(function(t){showNotification(t.message,"success"),updateCartDiv()}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}),$(document).on("click","#empty-cart",function(t){$.ajax({method:"POST",url:"/product/emptycart"}).done(function(t){updateCartDiv(),showNotification(t.message,"success",!0)})}),$(".qty-btn-minus").on("click",function(){var t=parseInt($("#product_quantity").val())-1;$("#product_quantity").val(t>0?t:1)}),$(".qty-btn-plus").on("click",function(){$("#product_quantity").val(parseInt($("#product_quantity").val())+1)}),$(".thumbnail-image").on("click",function(){$("#product-title-image").attr("src",$(this).attr("src"))}),$(document).on("click","#btn_search_reset",function(t){window.location.replace("/")}),$(document).on("click","#btn_search",function(t){t.preventDefault(),""===$("#frm_search").val().trim()?showNotification("Please enter a search value","danger"):window.location.href="/search/"+$("#frm_search").val()}),""!==$("#input_notify_message").val()){var s=$("#input_notify_message").val(),c=$("#input_notify_messageType").val();$("#input_notify_message").val(""),$("#input_notify_messageType").val(""),showNotification(s,c||"danger",!1)}}); \ No newline at end of file diff --git a/routes/index.js b/routes/index.js index 1a1095a..2f02484 100644 --- a/routes/index.js +++ b/routes/index.js @@ -95,7 +95,6 @@ router.get('/checkout/information', async (req, res, next) => { config: req.app.config, session: req.session, paymentType, - cartSize: 'part', cartClose: false, page: 'checkout-information', countryList, @@ -124,12 +123,21 @@ router.get('/checkout/shipping', async (req, res, next) => { return; } + // Net cart amount + const netCartAmount = req.session.totalCartAmount - req.session.totalCartShipping || 0; + + // Recalculate shipping + config.modules.loaded.shipping.calculateShipping( + netCartAmount, + config, + req + ); + // render the payment page res.render(`${config.themeViews}checkout-shipping`, { title: 'Checkout', config: req.app.config, session: req.session, - cartSize: 'part', cartClose: false, cartReadOnly: true, page: 'checkout-shipping', @@ -146,7 +154,6 @@ router.get('/checkout/cart', (req, res) => { res.render(`${config.themeViews}checkout-cart`, { page: req.query.path, - cartSize: 'full', config, session: req.session, message: clearSessionValue(req.session, 'message'), @@ -189,7 +196,6 @@ router.get('/checkout/payment', (req, res) => { session: req.session, paymentPage: true, paymentType, - cartSize: 'part', cartClose: true, cartReadOnly: true, page: 'checkout-information', diff --git a/views/layouts/layout.hbs b/views/layouts/layout.hbs index c8c72da..ee0da30 100644 --- a/views/layouts/layout.hbs +++ b/views/layouts/layout.hbs @@ -139,7 +139,7 @@
{{> (getTheme 'cart')}}
-
+
Checkout
diff --git a/views/themes/Cloth/cart.hbs b/views/themes/Cloth/cart.hbs index b56c08e..427daba 100644 --- a/views/themes/Cloth/cart.hbs +++ b/views/themes/Cloth/cart.hbs @@ -1,7 +1,7 @@
{{ @root.__ "Cart contents" }}
-
+
{{#each @root.session.cart}}
@@ -47,11 +47,11 @@
{{/each}}
-
+
{{#if @root.session.cart}}
- {{#ifCond @root.session.shippingCostApplied '===' true}} + {{#ifCond @root.session.totalCartShipping '>' 0}}
{{ @root.__ "Shipping" }} {{currencySymbol @root.config.currencySymbol}}{{formatAmount @root.session.totalCartShipping}} diff --git a/views/themes/Cloth/checkout-cart.hbs b/views/themes/Cloth/checkout-cart.hbs index d264b87..afdffba 100644 --- a/views/themes/Cloth/checkout-cart.hbs +++ b/views/themes/Cloth/checkout-cart.hbs @@ -3,7 +3,7 @@
{{> (getTheme 'cart')}}
-
+
Checkout
diff --git a/views/themes/Cloth/checkout-information.hbs b/views/themes/Cloth/checkout-information.hbs index 01ffaea..c028ad2 100644 --- a/views/themes/Cloth/checkout-information.hbs +++ b/views/themes/Cloth/checkout-information.hbs @@ -88,7 +88,7 @@ {{> (getTheme 'cart')}} {{#if @root.session.cart}}
-
+
{{/if}} diff --git a/views/themes/Cloth/checkout-payment.hbs b/views/themes/Cloth/checkout-payment.hbs index ce74d3d..39712d0 100644 --- a/views/themes/Cloth/checkout-payment.hbs +++ b/views/themes/Cloth/checkout-payment.hbs @@ -23,7 +23,7 @@
    - {{#if @root.session.shippingCostApplied}} + {{#ifCond @root.session.totalCartShipping '>' 0}}
  • @@ -37,7 +37,7 @@
  • {{else}}
  • FREE shipping Change
  • - {{/if}} + {{/ifCond}}
{{#if session.customerPresent}} diff --git a/views/themes/Cloth/checkout-shipping.hbs b/views/themes/Cloth/checkout-shipping.hbs index 089c274..714baf0 100644 --- a/views/themes/Cloth/checkout-shipping.hbs +++ b/views/themes/Cloth/checkout-shipping.hbs @@ -14,11 +14,11 @@
{{ @root.__ "Shipping options" }}
{{#unless @root.session.shippingOptions}}
    - {{#if @root.session.shippingCostApplied}} -
  • Standard shipping {{currencySymbol @root.config.currencySymbol}}{{formatAmount @root.session.totalCartShipping}}
  • + {{#ifCond @root.session.totalCartShipping '>' 0}} +
  • {{@root.session.shippingMessage}} {{currencySymbol @root.config.currencySymbol}}{{formatAmount @root.session.totalCartShipping}}
  • {{else}}
  • FREE shipping
  • - {{/if}} + {{/ifCond}}
{{/unless}}
@@ -29,7 +29,7 @@
{{> (getTheme 'cart')}}
-
+