"Restricting Countries" bug in Firefox

fewdiodavefewdiodave Member
in Bugs & Feature Requests edited September 2014
I'm running a 0.7.2 shop at www.sarahhorowitz.com. I have used the snippet at the bottom of my post to restrict countries to the U.S. and Canada. It works fine in most browsers, but a bug seems to have popped up in Firefox. As soon as a customer using Firefox enters their state, the popup "We only ship to U.S. and Canada" message fires. If you just click "Okay" on the error message and enter your zip code, it functions correctly and the sale can be completed. But it's causing confusion with customers who just stop there and email us telling us they can't order. I'm scared to think about how many customers just don't even bother and we lose the sale.

Any insight?

Thanks for any help!
<script type="text/javascript" charset="utf-8">
jQuery(document).ready(function(){
  // Restrict the locations array
  var newLocations = [];
  var allowedCountries = ["US", "CA"];
  for (var i = 0; i < FC.locations.config.locations.length; i++) {
    if (jQuery.inArray(FC.locations.config.locations[i].cc2, allowedCountries) > -1) {
      newLocations.push(FC.locations.config.locations[i]);
    }
  }

  FC.locations.config.locations = newLocations;
  FC.locations.init(); // Update the countries and regions based on the modified locations array
  FC.checkout.setAutoComplete("customer_country");
  FC.checkout.setAutoComplete("customer_state");
  FC.checkout.setAutoComplete("shipping_country");
  FC.checkout.setAutoComplete("shipping_state");

  // Default to the US if not within our allowed countries
  if (jQuery.inArray(jQuery("#customer_country").val(), allowedCountries) == -1) {
    jQuery('#customer_country, #shipping_country').val('US');
    jQuery('#customer_country_name, #shipping_country_name').val('United States');
  }

  // Apply custom code to validateLocationName to alert when an unsupported country is typed in
  defaultValidateLocationName = FC.checkout.validateLocationName;

  customValidateLocationName = function(fieldName) {
    fieldName = fieldName[0];
    if (fieldName.indexOf("country") != -1) {
      var fieldValue = jQuery("#"+fieldName+"_name").val();
      var countryFound = false;
      for (var i = 0; i < FC.locations.config.locations.length; i++) {
        if (FC.locations.config.locations[i].cn == fieldValue) {
          countryFound = true;
        }
      }
    }

    if (!countryFound) {
      alert("We only ship to U.S. and Canada");
    }

    // Call the default function
    defaultValidateLocationName(fieldName);
  }

  FC.checkout.override("validateLocationName", "customValidateLocationName");

});
</script>
Comments
  • fc_adamfc_adam FoxyCart Team
    @fewdiodave,

    I just tested your checkout on FireFox version 31, and I don't see the alert displaying on page load. Can you reproduce this yourself? If so, what version are you running?
Sign In or Register to comment.