Foxy Forum Status

We're no longer responding to questions via our forum, but we will keep it up for historical reasons. If you can't find the answer you're looking for, please visit our knowledge base or contact us. If there's enough interest in the future, we may bring the forum back.

Shipping Rate Incorrectly Calculated (Sometimes) - JavaScript Blocked?

rainleaderrainleader Member
in Help edited December 2012
I have the following custom shipping logic setup in the store at http://lavajavamaui.com:
<script type="text/javascript" charset="utf-8">
FC.checkout.config.customShipping = {
  onLoad: true,  // Set to false if you don't want shipping calculated when the checkout loads
  onLocationChange: true // Set to true if your shipping logic relies on updating whenever the shipping location for the order changes
};
 
function calculateShipping() {
  var shippingCost = 0;
 
/* BEGIN CUSTOM SHIPPING LOGIC */
shippingCost = 12;
 
var coffeeProducts = 0;
for (var p in fc_json.products) {
	if (fc_json.products[p].category == "coffee") {
		coffeeProducts += fc_json.products[p].quantity;
 
	}
}
 
if (coffeeProducts > 0) {
	if (coffeeProducts == 1) {
		shippingCost = 5 ; // $5 for one coffee product
	} else if (coffeeProducts < 6) {
		shippingCost = 11; // $11 for less than 6 coffee products
	} else { // free for more than 6 coffee products
		shippingCost = 0; // Free shipping because they bought so much
	}
}

if (fc_json.hasOwnProperty('coupons')) {
        shippingCost = 11;
}

The shipping should be:

1 bag of coffee= $5.00
2-5 bags of coffee = $11
6+ bags of coffee= FREE

For some reason, there is an occasional user who purchases a few bags of coffee and gets FREE shipping. Can't figure out why. Is it possible that blocking Javascript would cause this?
Comments
  • fc_adamfc_adam FoxyCart Team
    @rainleader,

    If javascript was blocked, the customer more than likely wouldn't be able to check out at all - as our checkout heavily relies on javascript.

    Could you whisper me the transaction id's for the transactions that didn't have shipping that should have?
  • fc_adamfc_adam FoxyCart Team
    @rainleader,

    I think this might come down to a 'console.log' function call in your custom shipping code - which if present some browsers will break at that point - which is right before the shippingCost is actually applied - which means shipping cost will stay at 0.

    Try removing that line, it looks like this:
    console.log(country_code);
    

    and let me know if any other orders come in where the total shipping is 0 when it shouldn't be.
  • Thanks! Removed it and will keep you updated.
Sign In or Register to comment.