The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

FC2.0 Custom Shipping Logic refresh

timconsidinetimconsidine Member
in Help edited October 2015
I am testing FC2 and have combined 2 example snippets for multiple shipping rates to different countries with free shipping over ##
It seems to work when the cart is first loaded, but if the quantity is changed or the ship destination is changed, it does not recalculate well, with shipping being left as TBD.
var tier1 = ['GB'];
var tier2 = ['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) {
// United Kingdom
if (FC.json.total_item_price >= 25) {
FC.customFlatRates.update(1, 0, 'Royal Mail', 'Signed For');
} else {
FC.customFlatRates.add(1, 4.95, 'Royal Mail', 'Signed For');
} else if (tier2.indexOf(address.country) > -1) {
// Europe
if (FC.json.total_item_price >= 25) {
FC.customFlatRates.update(2, 0, 'Royal Mail', 'International');
} else {FC.customFlatRates.add(2, 8.00, 'Royal Mail', 'International');
} else {
// Rest of world
if (FC.json.total_item_price >= 25) {
FC.customFlatRates.update(3, 0, 'Royal Mail', 'International');
} else {FC.customFlatRates.add(3, 10.00, 'Royal Mail', 'International');
}
Is there a variable to be reset or an update call needed ?

Also moving to the checkout, the customer is able to change the quantity even at this stage, but I don't think the cart custom logic is being called. Can it be called or can I just disable editing of cart contents or quantity ?

Your help & advice much appreciated
Comments
  • Further testing suggests that possibly FC.json.total_item_price is not being refreshed or updated.
    It seems to survive an initial change to quantity, but repeated quantity changes or shipping destination changes seem to confuse it.
    Could this be the case ? Suggestions for forcing a refresh, or debugging ?
  • So .... mostly user error again ! (((

    Here is my corrected custom logic, major changes being correction to nested if brackets, and a reset call for custom rates to prevent pollution from previous cart values

    I have also incorporated a tiered minimum spend for free shipping based on region by tweaking values
        /* BEGIN CUSTOM SHIPPING LOGIC */
    FC.customFlatRates.reset();
    FC.customFlatRates.add(1, 4.95, 'Royal Mail', 'GB Signed For');
    // FC.customFlatRates.add(2, 7.95, 'Royal Mail', 'EU Tracked');
    // FC.customFlatRates.add(3, 9.95, 'Royal Mail', 'RoW Tracked');

    var tier1 = ['GB'];
    var tier2 = ['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) {
    // United Kingdom
    if (FC.json.total_item_price >= 25) {
    FC.customFlatRates.update(1, 0, 'Royal Mail', 'GB Signed For');
    } else {
    FC.customFlatRates.update(1, 4.95, 'Royal Mail', 'GB Signed For');}
    } else if (tier2.indexOf(address.country) > -1) {
    // Europe
    if (FC.json.total_item_price >= 30) {
    FC.customFlatRates.update(1, 0, 'Royal Mail', 'EU Tracked');
    } else {FC.customFlatRates.update(1, 7.95, 'Royal Mail', 'EU Tracked');}
    } else {
    // Rest of world
    if (FC.json.total_item_price >= 40) {
    FC.customFlatRates.update(1, 0, 'Royal Mail', 'RoW Tracked');
    } else {FC.customFlatRates.update(1, 9.95, 'Royal Mail', 'RoW Tracked');}
    }


    /* END CUSTOM SHIPPING LOGIC */
    I believe this now works, testing continue
  • fc_jedfc_jed FoxyCart Team
    We're glad you were able to resolve your issue. Do let us know if you run into additional concerns in the future.
  • Having sweated over customisations for my FC1.1 implementation, I have been very nervous of changes to FC2 and have been delaying the day.

    BUT ..... it's really sweet ! Thank you !

    I am mightily impressed by the EU VAT integration, and the shipping snippets are great for my needs.

    Now, when you finish that tax-inclusive pricing feature, that will be awesome !

    Thanks, guys
Sign In or Register to comment.