I am trying some complicated maneuvering with with the Live Rate Shipping Modification snippet, and it seems to do some strange things when I change the address. Is there a way to make it run again when the address is changed? I've seen the onLocationChange option for some of the other snippets, but my javascript knowledge is limited and I'm not sure how to apply that to the FC.customLiveShipping script. Or if there's some equivalent already in place in that snippet, perhaps it is not the cause of my problem.
The script is copied directly from the Live Shipping Rate Modification (
https://wiki.foxycart.com/snippets/shipping/live_rate_shipping_modification), and I have only changed stuff in the custom shipping logic area.
What happens is like this:
When I put in an address in France, I get the correct shipping cost and everything looks good. Then, if I simply change the address to one in Canada, the cost next to "Shipping Methods" is more than twice what it should be, while the cost next to "Shipping & Handling" is much too low. Not to mention that the two don't match. :-) If I refresh the checkout page and put in the Canada address, I get correct and matching amounts.
Any thoughts?
The live rate shipping modification snippet should re-run your logic whenever new rates are fetched - which is whenever you change the shipping address. That should all happen automatically already.
Could you let us know what store this is for and what addresses we can use to replicate what you're seeing? Feel free to whisper it if it's private.
I did some more testing, and it looks like the problem is only with items in certain categories, so I think it's actually a problem with a section of my custom logic. The wonky section is this:
What I'm trying to do is modify this script: https://wiki.foxycart.com/snippets/shipping/breaking_shipments_over_maximum_weight_into_smaller_packages so that it takes the total weight and divides it by the number of packages to get the average package weight, then sends that to the carrier and multiplies the returned rate by the number of packages and adds a $5 handling fee. I obviously don't know what I'm doing, because this code spits out a number that's pretty far off, and it also causes the problem described before when I change the shipping country.
if (countLarge > 0) {
//if any LARGE items are present, break into multiple packages and add $5 to total shipping cost
jQuery(document).ready(function() {
var package_count = countLarge + countLargeAccessories;
// sets average_weight to expected total weight
var average_weight = fc_json.total_weight;
if (package_count > 1) {
average_weight = fc_json.total_weight/package_count;
FC.checkout.config.orderLiveRateShipmentWeight = average_weight;
}
jQuery(document).ajaxComplete(function(event, request, settings) {
if (settings.url.indexOf('GetShippingCost') != -1) {
jQuery("#fc_shipping_methods_inner input.fc_radio").each(function() {
var rate = jQuery(this).val().split("|");
var adjusted_total = (parseFloat(rate[1]) * package_count) + 5;
jQuery(this).val(rate[0] + "|" + adjusted_total).siblings(".fc_shipping_cost").html(FC.formatter.currency(adjusted_total, true));
});
}
});
});
}
Ah yep - that would be an issue, it's not quite as simple as just pasting that other snippet into the custom logic of the live rate shipping modification. You'll need to break part of your logic out into it's own script block, and change the other logic to match how the live shipping rate modification snippet works:
Paste this before the shipping modification snippet script block:
And then update your custom shipping logic code like this:
I haven't tested that, so make sure you give it a good test - but that should work.
It does appear to function, and does not give me any problems when I change shipping addresses, but I'm not sure it's doing quite what I want. Can you explain what these lines are doing?
FC.customLiveShipping.update("all", "*" + package_count);
FC.customLiveShipping.update("all", "+5");
Is that actually multiplying the returned rate by package_count and then adding $5? If I do a test with two 27 lb. large items (total weight = 54 lbs, package_count should be 2), the total cost that's returned is about $15 higher than if I look it up directly with USPS.
If I test with a single large item, the calculated cost is about $10 higher than it should be.
Is there any way for me to tell whether this is something in the script vs. something to do with how rates are looked up with USPS?
Thanks for fixing it for me!
Happy to help!