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.

Custom flat rate shipping code

Hello,

I'm trying to setup some custom flat rate shipping info. So, I did the following:

1. I setup a 'cart include' template to which I added the flat rate shipping javascript snippet to
2. I used an example provided in the custom shipping logic area of the code and I tested it and it worked fine
3. I tried to do some custom JavaScript and I added it and it isn't working now, so, I obviously messed things up. I am not a seasoned veteran with JavaScript by any stretch of the imagination and I'm sure there may be more than one error.

So, if anyone has a moment to look at my script and tell me what I did wrong, I would be very grateful. Thanks in advance..

Here it is:
var tier1 = [‘CA’];
var tier2 = [‘US’];
var tier3 = ['AL', 'AD', 'AM', 'AT', 'BY', 'BE', 'BA', 'BG', 'CH', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FO', 'FI', 'FR', 'GB', 'GE', 'GI', 'GR', 'HU', 'HR', 'IE', 'IS', 'IT', 'LT', 'LU', 'LV', 'MC', 'MK', 'MT', 'NO', 'NL', 'PL', 'PT', 'RO', 'RU', 'SE', 'SI', 'SK', 'SM', 'TR', 'UA', 'VA'];
 
if (tier1.indexOf(address.country) > -1) {
// Canada
FC.customFlatRates.add(1, 28, ‘DHL’, ‘International Standard (5-7 Days)’);
FC.customFlatRates.add(2, 36, ‘DHL’, ‘International Express (2-4 Days)’);
} else if (tier2.indexOf(address.country) > -1) {
// US
FC.customFlatRates.add(3, 28, ‘DHL’, ‘International Standard (5-7 Days)’);
FC.customFlatRates.add(4, 38, ‘DHL’, ‘International Express (2-4 Days)’);
} else if (tier3.indexOf(address.country) > -1) {
// Europe
FC.customFlatRates.add(5, 26, ‘DHL’, ‘International Standard (5-7 Days)’);
FC.customFlatRates.add(6, 28, ‘DHL’, ‘International Express (2-4 Days)’);
}

var tWeight = FC.json.total_weight;
var tPrice;
var tPriceFix;

if (tWeight > 100) {
tPrice = 4.99 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(1, tPriceFix);
tPrice = 5.39 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(2, tPriceFix);
tPrice = 4.89 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(3, tPriceFix);
tPrice = 5.89 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(4, tPriceFix);
tPrice = 4.69 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(5, tPriceFix);
tPrice = 5.69 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(6, tPriceFix);
} else if (tWeight > 80) {
tPrice = 5.19 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(1, tPriceFix);
tPrice = 4.99 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(3, tPriceFix);
tPrice = 4.89 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(5, tPriceFix);
} else if (tWeight > 50) {
tPrice = 5.39 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(1, tPriceFix);
tPrice = 5.39 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(2, tPriceFix);
tPrice = 5.19 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(3, tPriceFix);
tPrice = 5.89 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(4, tPriceFix);
tPrice = 5.29 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(5, tPriceFix);
tPrice = 5.69 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(6, tPriceFix);
} else if (tWeight > 21) {
tPrice = 5.69 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(1, tPriceFix);
tPrice = 5.99 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(2, tPriceFix);
tPrice = 5.49 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(3, tPriceFix);
tPrice = 5.89 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(4, tPriceFix);
tPrice = 5.89 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(5, tPriceFix);
tPrice = 6.29 * tWeight;
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(6, tPriceFix);
} else if (tWeight > 1) {
tPrice = (34 + (5 * tWeight));
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(1, tPriceFix);
tPrice = (48 + (6 * tWeight));
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(2, tPriceFix);
tPrice = (28 + (5 * tWeight));
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(3, tPriceFix);
tPrice = (50 + (6 * tWeight));
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(4, tPriceFix);
tPrice = (28 + (5 * tWeight));
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(5, tPriceFix);
tPrice = (40 + (6 * tWeight));
tPriceFix = tPrice.toFixed(2);
FC.customFlatRates.update(6, tPriceFix);
} else if (tWeight > .5) {
FC.customFlatRates.update(1, 34);
FC.customFlatRates.update(2, 48);
FC.customFlatRates.update(3, 28);
FC.customFlatRates.update(4, 50);
FC.customFlatRates.update(5, 32);
FC.customFlatRates.update(6, 40);
}
Comments
  • lukeluke FoxyCart Team
    Hello @pockethigh. In the future it's helpful to include a link to your store so others can take a look and help you test it.

    When I load up your checkout, I see this error in the chrome console:

    http://screencast.com/t/zJY6AK00TsH

    When I click on that, I see this:

    http://screencast.com/t/f5VJhZkV

    It looks like you're using some invalid quote characters there:

    var tier1 = [‘CA’];
    var tier2 = [‘US’];
    This should instead be:

    var tier1 = ['CA'];
    var tier2 = ['US'];
    Hope that helps.
  • Hi Luke,

    Thanks so much.

    That kind of worked. When I have a total weight of less than 0.5kgs it loads the correct shipping data, but if it is heavier than that, it either thinks forever or just says "Please enter your location information to display your shipping options."

    Here is a link to my website: www.litelumens.com
  • pockethighpockethigh Member
    edited May 2015
    I just tried to gather some extra info by adding this in the header:
    <script>
    var FC = FC || {};
    FC.override = FC.override || {};
    FC.override.debug = true;
    </script>
    And thereafter, it was working.....??? So just to double check, I removed the debug script from the header and I'm back to square one.. This is a bit mysterious, no?
  • I haven't changed anything and it appears to be working now... Thanks Luke
Sign In or Register to comment.