Ship options... home stretch.. help!

purpleontimepurpleontime Member
in Help edited September 2015
Hi guys. trying not to get frustrated, in the home stretch, but the shipping has me flustered.
All I need is:

-Flat rate, USA (usps priority)

-Flat rate, Intl (usps priority intl)

-based on customer's address

-allow them to see both options in the mini cart

thats it! shipping snippets got me stumped.
please help.
thx

*just to clairify, I have 2 rates. a domestic, and a worldwide rate. thats it
Comments
  • fc_adamfc_adam FoxyCart Team
    @purpleontime,

    Sorry to hear you're having trouble - we're happy to help!

    This is the snippet you'll need - assuming you're on a 2.0 store: https://wiki.foxycart.com/v/2.0/snippets/flat_rate_shipping_modification

    The 3rd example at the bottom will be essentially what you need for the custom logic. The only real difference is that it has 2 rates displaying for domestic. You may not need the equation that's calculating the rate either.

    The only thing that you may have trouble with there is your last two requirements. You want it to be based on the address - so I'm guessing you mean it will only show domestic for domestic orders, and international for international orders. You also then talk about having both options visible on the cart. Is that correct?

    If you need any help getting the logic customised, just let us know what prices the rates should be and we can help with that.
  • Hi Adam. Thx.
    I'd like it to be $4.99 Domestic (Any USA address) and $34.99 Worldwide.
    I assume if I use the list in the excluded-country section of my cart setup, it will automatically let the customer know if they are in a "no ship" country, correct?

    With the mini-cart, I'd like it to default to the USA ship (which it does already) and have the option to pop in another country, or simply "Worldwide" or something to show the ship rate (maybe a dropdown that simple says, "Worldwide"?), I don't need a total list of countries.

    I like that the minicart displays the entire total so the customer isn't "surprised" by the ship rates on checkout, like it does now.

    Please answer ASAP. I'm supposed to have it done yesterday!
    Thx so much for the help.
    -matt




  • fc_adamfc_adam FoxyCart Team
    @purpleontime,

    Sure thing - so the custom logic when the instructions ask for it would be this:
    if (address.country == "US") {
    FC.customFlatRates.add(1, 4.99, 'USPS', 'Priority');
    } else {
    FC.customFlatRates.add(2, 34.99, 'USPS', 'Priority International');
    }
    I assume if I use the list in the excluded-country section of my cart setup, it will automatically let the customer know if they are in a "no ship" country, correct?
    Are you referring to the location whitelist/blacklist functionality? If so - if you remove a country or state from your store - the customer simply won't be able to select that specific location.
    With the mini-cart, I'd like it to default to the USA ship (which it does already) and have the option to pop in another country, or simply "Worldwide" or something to show the ship rate (maybe a dropdown that simple says, "Worldwide"?), I don't need a total list of countries.
    The country will default to be based on the customers IP - so if the customer is visiting from Japan, they'll see Japan as the country. The customer can change the country from the cart to change their address and receive different shipping costs.
  • purpleontimepurpleontime Member
    edited September 2015
    The country will default to be based on the customers IP - so if the customer is visiting from Japan, they'll see Japan as the country. The customer can change the country from the cart to change their address and receive different shipping costs.
    thank you. any idea how I can test this? spoof the browser to trick foxy to think I'm visiting the site from another country to be sure it is working correctly?

    Also, what if the person has locations tracking turned off?
  • fc_adamfc_adam FoxyCart Team
    @purpleontime,

    For testing it - you could use a VPN or similar to pass your traffic through a different IP, or if you know someone overseas, you can simply ask them to load up your checkout and see the country auto-selected.

    As an example, I'm based in Australia and when I visit a FoxyCart based checkout I see Australia auto-selected.
    Also, what if the person has locations tracking turned off?
    We base it on the IP - so it's not something that a user can turn off. If an IP address doesn't match to a country based on the GeoIP search though, we currently default the country to be the US. We'll be improving that in the future though to default to the store country instead.
  • Hi Adam, thx for the help.
    I guess an easy solution would be... Would you mind hitting the page and adding the item to your cart? Just to make sure it calculates ship for worldwide since you're in Australia?
    The link is earlier in this post.
  • fc_adamfc_adam FoxyCart Team
    @purpleontime,

    I might be missing something right in front of my face here, but I'm not seeing any links in this thread.
  • fc_adamfc_adam FoxyCart Team
    edited September 2015
    @purpleontime,

    The checkout is defaulting to Australia for me - you can see that here

    For the shipping - you've made use of an older snippet which isn't valid for 2.0. You need to make use of this snippet: https://wiki.foxycart.com/v/2.0/snippets/flat_rate_shipping_modification

    For what it's worth, you should also be able to test any shipping snippets yourself just by changing the country and address details on the checkout.
  • Hi. I didn't use any snippets other than the one you told me to change so I'm not sure what you mean.
    I couldn't have put an older snippet, because I wouldn't even know how to do it on purpose.
    Can you be more specific or simply give me a copy-paste to reset?
  • fc_adamfc_adam FoxyCart Team
    @purpleontime,

    The store that the add to cart points to on the website you linked me to, that doesn't have the snippet on there that I provided you earlier. Instead it has this snippet which is for older versions of FoxyCart and isn't compatible with 2.0:
    <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: false // 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 */

    if (address.country == "US") {
    FC.customFlatRates.add(1, 4.99, 'USPS', 'Priority');
    } else {
    FC.customFlatRates.add(2, 34.99, 'USPS', 'Priority International');
    }

    /* END CUSTOM SHIPPING LOGIC */

    FC.checkout.config.orderFlatRateShipping = shippingCost;
    FC.checkout.updateShipping(-1);
    }

    jQuery(document).ready(function() {
    if (FC.checkout.config.customShipping.onLoad) {
    runShippingLogic();
    }

    if (FC.checkout.config.customShipping.onLocationChange) {
    FC.checkout.overload("updateTaxes", function() { runShippingLogic(); }, null);
    }
    });

    function runShippingLogic() {
    // Check to see if there are actually shippable products in the current cart before running the custom shipping (0.7.1+ only), or just run it for older carts
    if ((typeof(FC.checkout.config.hasShippableProducts) === "boolean" && FC.checkout.config.hasShippableProducts) || typeof(FC.checkout.config.hasShippableProducts) === "undefined") {
    calculateShipping();
    }
    }
    </script>
    You'll need to remove that code from your checkout template and then follow the instructions on the wiki page I linked to above. On the step where it asks for the custom shipping logic you can use the code I also provided earlier in this thread.
  • I don't understand. I am new to foxycart, so how could I have used an "old version"?
    I only have the code that came with the cart by default?
  • fc_adamfc_adam FoxyCart Team
    edited September 2015
    @purpleontime,

    This code that I pasted above doesn't come with the cart at all - it's custom code that needs to be pasted in. You are definitely on the latest version of FoxyCart. The custom code that you've added though - that is the "old version" that I'm referring to. It's a custom snippet that was made for older versions of FoxyCart, so when applied to the latest version it doesn't work.

    Could you let me know which page you copied the code you added to your checkout from?
  • Thats what I mean. I didn't copy paste it. Just to be clear, I should paste in the code from above to the "cart" custom template, right? or are you showing me what is wrong in the code above?
  • If I go to "responsiv template" on the checkout, then go back to "custom template" it shows this:

    <!DOCTYPE html>
    <html id="fc">
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>{{ config.store_name }} Secure Checkout</title>

    <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui">

    <!--[if lt IE 9 ]>
    <script type="text/javascript">
    var IEElms = ['article', 'aside', 'header', 'main', 'nav', 'section'];
    for (var i = 0; i < IEElms.length; i++) {
    document.createElement(IEElms[i]);
    };
    </script>
    <![endif]-->

    <link href="{{ config.css_file }}" rel="stylesheet" media="screen">

    <!-- FC script insertion -->{{ fc_header_content|raw }}<!-- /FC script insertion -->
    <!--[if lt IE 9 ]>
    <script src="{{ config.cdn_static_path }}scripts/respond/respond.1.4.2.js" charset="utf-8"></script>
    <style>
    #fc label.fc-form-label--with-placeholder {
    display:block !important;
    left:0 !important;
    width:auto !important;
    height:50px !important;
    clip:auto !important;
    position:relative !important;
    text-align:left !important;
    }
    </style>
    <![endif]-->
    </head>
    <body>
    <!-- has to be here because of chrome bug -->
    {% include 'svg.inc.twig' %}

    {% import "utils.inc.twig" as utils %}
    {% embed 'checkout.inc.twig' %}
    {% endembed %}

    <!-- FC footer script insertion -->{% include template_from_string(fc_footer_content) %}<!-- /FC footer scripts -->
    <!--[if lt IE 10 ]>
    <script src="//{{ config.store_domain }}/static/scripts/placeholder/placeholder_polyfill.jquery.js" charset="utf-8"></script>
    <![endif]-->
    </body>
    </html>
  • cart:

    <!DOCTYPE html>
    <html id="fc">
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>{{ config.store_name }} Cart</title>

    <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui">
    <!--[if lt IE 9 ]>
    <script type="text/javascript">
    var IEElms = ['article', 'aside', 'header', 'main', 'nav', 'section'];
    for (var i = 0; i < IEElms.length; i++) {
    document.createElement(IEElms[i]);
    };
    </script>
    <![endif]-->
    <link href="{{ config.css_file }}" rel="stylesheet" media="screen">
    <!-- FC script insertion -->{{ fc_header_content|raw }}<!-- /FC script insertion -->
    <!--[if lt IE 9 ]>
    <script src="{{ config.cdn_static_path }}scripts/respond/respond.1.4.2.js" charset="utf-8"></script>
    <style>
    #fc label.fc-form-label--with-placeholder {
    display:block !important;
    left:0 !important;
    width:auto !important;
    height:50px !important;
    clip:auto !important;
    position:relative !important;
    text-align:left !important;
    }
    </style>
    <![endif]-->
    </head>
    <body class="fc-context--cart-fullpage" data-fc-context='{"cart_is_fullpage":true}'>

    {% set cart_is_fullpage = true %}
    <div data-fc-container="cart">
    {% embed 'cart.inc.twig' %}
    {% endembed %}
    </div>



    <!-- FC footer script insertion -->{% include template_from_string(fc_footer_content) %}<!-- /FC footer scripts -->
    </body>
    </html>
  • fc_adamfc_adam FoxyCart Team
    @purpleontime,

    Does anyone else have access to your store login that may have customised your template? Looking at the store change log, I can see the code I pasted above being added to the "cart include" template by the user account with access to your store. There are also edits around the same time to other templates.

    The code I pasted above is the old snippet which is on your template. That code is still present in your "cart" template, and will need to be removed.

    What I'd suggest doing is this. Unless you're applying some other customisations directly to your cart or checkout templates, I'd recommend setting both of them to be the standard "responsive" templates by clicking that radio button for each template and saving. Then follow the steps detailed on this page: https://wiki.foxycart.com/v/2.0/snippets/flat_rate_shipping_modification
  • I am the only one that uses this.
  • are we talkig about "cart include" or "cart"?
  • fc_adamfc_adam FoxyCart Team
    @purpleontime,

    Looking at the store change log, from what I can see the javascript snippet I'm referring to above was first added to the "cart include" template, then removed, then added to the "cart" template where it still remains.
  • where should it be, is what I'm saying? I'm a bit turned around now
  • fc_adamfc_adam FoxyCart Team
    @purpleontime,

    Sorry for the confusion. I'll try to run through it again entirely to hopefully bring clarity.

    You've added some custom code to your store, which is currently added to the cart template. It looks like this: http://pastie.org/private/bz4qsdyoeubzmt1qurw5w

    This code is not the correct code that you need for your store version. So that needs to be removed from your store. If you haven't made any other changes to your cart template - simply set it to "Responsive" and save the template. If you have made other changes you need to maintain, you'll need to remove the code detailed in that link above and save the template.

    Once you've done that - follow the steps detailed on this page: https://wiki.foxycart.com/v/2.0/snippets/flat_rate_shipping_modification

    That link will walk you through what you need to do and what you need to add where. In step 3, use this code:
    if (address.country == "US") {
    FC.customFlatRates.add(1, 4.99, 'USPS', 'Priority');
    } else {
    FC.customFlatRates.add(2, 34.99, 'USPS', 'Priority International');
    }
  • What I think is happening, is that when I click to "responsive', the "custom" resets itself, but it is resetting to the old version. I tried to follow the instructions in the link but they are very confusing.
  • fc_adamfc_adam FoxyCart Team
    @purpleontime,

    When you set the template to "responsive" make sure you also click "Update template" to save the change. Otherwise it will just stay on the custom template you've currently set.

    In terms of the instructions in the link - let us know which steps you're having trouble with and we'll be happy to help you out.
  • I thought it automatically grabbed the location?
    yes, please put in the footer for me. that'd be great
  • fc_adamfc_adam FoxyCart Team
    @purpleontime,

    I just took a look at your store to add it - but I see you've set everything up correctly. The templates are set to default and the code is included in the custom configuration footer setting. Loading your cart and it's sliding in as expected and allows me to enter an address to fetch shipping costs.
    I thought it automatically grabbed the location?
    The country is set automatically by IP address, but the shipping relies on the postcode as well.
Sign In or Register to comment.