Country codes - issue regarding Northern Ireland

intandemintandem Member
in Help edited October 2012
I am setting up a shop that ships to Ireland and Northern Ireland only.

It seems that Northern Ireland doesn't have its own ISO code and is considered a "province" of Great Britain, ie. it comes under the "GB" ISO code. However, for logistical reasons, I cannot use this as one of the countries this shop is limited to shipping to, as they do not ship to the rest of the UK. In addition, for political reasons it would also not be desirable to show "Great Britain" on the dropdown anyway as this would be deemed offensive to some people (in the same way as leaving it only as "Ireland" to cover all counties on the island would be offensive to others).

Is there any way to overcome this?
Comments
  • lukeluke FoxyCart Team
    I think @fc_adam will follow up on your other post which has a lot more details. He may be out for a day or two on a mini-vacation, but will get back to you as soon as he's available.
  • fc_adamfc_adam FoxyCart Team
    @intandem,

    There are two ways you could approach this. Firstly, as I mentioned on your other post, you could add some additional custom logic that if the UK is selected that the county field is pre-filled with "Northern Ireland" to restrict it to just that part of the UK. Secondly, you could also change the names of the "UK" entry in the locations object to remove any other names for it and only show "Northern Ireland", so when someone types in "UK", "GB" etc, they won't see any results.
  • intandemintandem Member
    edited October 2012
    I now have the following code combination inserted into my shop. Part 1 to restrict to Ireland and UK, with UK only Northern Ireland allowed. Part 2 to generate shipping flat rate fees. Part 3 to remove country flags.

    Obviously this does not work at the moment because the county codes for Ireland are not yet set up on FoxyComplete and the system would also not understand a county code for Northern Ireland. Do I understand that correctly? Is there anything else I can do from my end? I need to figure out if FoxyCart can meet these shipping requirements pretty much by the end of the week or I will need to find a completely different shopping cart solution (this shop needs to go live in early November for the Christmas market). I keep my fingers crossed because FoxyCart has always been my preferred cart as it works so well with MODX! All of your fantastic help is appreciated, Adam.

    By the way, I am happy to pay someone to help me with this!

    Code in next post as too long otherwise.
  • intandemintandem Member
    edited October 2012
    <!-- CUSTOM LOCATION LOGIC 
    ==============================================-->
    
    <script type="text/javascript" charset="utf-8">
    	//<![CDATA[
    	jQuery(document).ready(function() {
     
    		/* BEGIN CUSTOM LOCATION LOGIC */
     
                    FC.locations.limitCountriesTo("IE","UK");
    		FC.locations.limitStatesTo("UK", "NI");
     
    		/* END CUSTOM LOCATION LOGIC */
     
    		FC.locations.updateFoxyComplete(true);
    	});
    	//]]>
    </script>
     
    <script type="text/javascript" charset="utf-8">
    	//<![CDATA[
    	// Country/State Helper Functions v1.0
    	// Do not modify the following functions
     
    	FC.locations.removeCountries = function(countries, locationArrayNames) {
    		if (typeof countries == "undefined") { return false }
    		if (typeof countries == "string") { countries = [countries]; }
    		locationArrayNames = FC.locations.validateLocationArrayNames(locationArrayNames);
     
    		for (l in locationArrayNames) {
    			var locationArray = FC.locations.getLocationArray(locationArrayNames[l]);
    			for (var c in countries) {
    				if (typeof locationArray[countries[c]] == "undefined") { break; }
    				delete locationArray[countries[c]];
    			}
    		}
     
    		return true;
    	}
     
    	FC.locations.limitCountriesTo = function(countries, locationArrayNames) {
    		if (typeof countries == "undefined") { return false }
    		if (typeof countries == "string") { countries = [countries]; }
    		locationArrayNames = FC.locations.validateLocationArrayNames(locationArrayNames);
     
    		for (l in locationArrayNames) {
    			var newLocations = {};
    			var locationArray = FC.locations.getLocationArray(locationArrayNames[l]);
    			for (var c in countries) {
    				if (typeof locationArray[countries[c]] == "undefined") { break; }
    				newLocations[countries[c]] = locationArray[countries[c]];
    			}
     
    			// Prevent the countries being set to nothing
    			if (newLocations == {}) { return false; }
     
    			if (locationArrayNames[l] == "customer") {
    				FC.locations.config.locations = newLocations;
    			} else {
    				FC.locations.config.shippingLocations = newLocations;
    			}
    		}
    		return true;
    	}
     
    	FC.locations.removeStates = function(country, states, locationArrayNames) {
    		if (typeof country == "undefined" || typeof states == "undefined") { return false }
    		if (typeof states == "string") { states = [states]; }
    		locationArrayNames = FC.locations.validateLocationArrayNames(locationArrayNames);
     
    		for (l in locationArrayNames) {
    			var locationArray = FC.locations.getLocationArray(locationArrayNames[l]);
    			if (typeof locationArray[country] == "undefined") { return false; }
    			for (var s in states) {
    				if (typeof locationArray[country].r[states[s]] == "undefined") { break; }
    				delete locationArray[country].r[states[s]];
    			}
    		}
    		return true;
    	}
     
    	FC.locations.limitStatesTo = function(country, states, locationArrayNames) {
    		if (typeof country == "undefined" || typeof states == "undefined") { return false }
    		if (typeof states == "string") { states = [states]; }
    		locationArrayNames = FC.locations.validateLocationArrayNames(locationArrayNames);
     
    		for (l in locationArrayNames) {
    			var newLocations = {};
    			var locationArray = FC.locations.getLocationArray(locationArrayNames[l]);
    			if (typeof locationArray[country] == "undefined") { return false; }
    			for (var s in states) {
    				if (typeof locationArray[country].r[states[s]] == "undefined") { break; }
    				newLocations[states[s]] = locationArray[country].r[states[s]];
    			}
     
    			if (locationArrayNames[l] == "customer") {
    				FC.locations.config.locations[country].r = newLocations;
    			} else {
    				FC.locations.config.shippingLocations[country].r = newLocations;
    			}
    		}
    		return true;
    	}
     
    	FC.locations.updateFoxyComplete = function(blockErrors) {
    		FC.checkout.setAutoComplete("customer_country");
    		if (jQuery("#customer_country_name") != "") {
    			FC.checkout.validateLocationName("customer_country");
    		}
    		if (jQuery("#customer_state_name").val() != "") {
    			FC.checkout.validateLocationName("customer_state");
    		}
    		if (blockErrors) {
    			FC.checkout.updateErrorDisplay("customer_country_name", false);
    			FC.checkout.updateErrorDisplay("customer_state_name", false);
    		}
    		if (!FC.checkout.config.hasMultiship) {
    			FC.checkout.setAutoComplete("shipping_country");
    			if (jQuery("#shipping_country_name") != "") {
    				FC.checkout.validateLocationName("shipping_country");
    			}
    			if (jQuery("#shipping_state_name") != "") {
    				FC.checkout.validateLocationName("shipping_state");
    			}
    			if (blockErrors) {
    				FC.checkout.updateErrorDisplay("shipping_country_name", false);
    				FC.checkout.updateErrorDisplay("shipping_state_name", false);
    			}
    		} else {
    			for (var i = 0; i < FC.checkout.config.multishipDetails.length; i++) {
    				FC.checkout.setAutoComplete("shipto_" + i + "_country");
    				if (jQuery("#shipto_" + i + "_country_name") != "") {
    					FC.checkout.validateLocationName("shipto_" + i + "_country");
    				}
    				if (jQuery("#shipto_" + i + "_state_name") != "") {
    					FC.checkout.validateLocationName("shipto_" + i + "_state");
    				}
    				if (blockErrors) {
    					FC.checkout.updateErrorDisplay("shipto_" + i + "_country_name", false);
    					FC.checkout.updateErrorDisplay("shipto_" + i + "_state_name", false);
    				}
    			}
    		}
    	}
     
    	FC.locations.getLocationArray = function(locationArrayNames) {
    		return (locationArrayNames == "customer") ? FC.locations.config.locations : FC.locations.config.shippingLocations;
    	}
     
    	FC.locations.validateLocationArrayNames = function(locationArrayNames) {
    		if (typeof locationArrayNames == "undefined" || locationArrayNames == "" || locationArrayNames == "both") { locationArrayNames = ["customer", "shipping"]; }
    		if (typeof locationArrayNames == "string") { locationArrayNames = [locationArrayNames]; }
    		return locationArrayNames;
    	}
    	//]]>
    </script>
    
  • <!-- CUSTOM SHIPPING LOGIC 
    ==============================================-->
    
    
    
    <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: true // 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 */
      
    			var country_code = (jQuery("#use_different_addresses").is(":checked") ? $("#shipping_country").val() : $("#customer_country").val());
    			var state_code = (jQuery("#use_different_addresses").is(":checked") ? $("#shipping_state").val() : $("#customer_state").val());
    			
    			var categories = [];
    			
    			for (var p in fc_json.products) {
    			  var pCat = fc_json.products[p].category;
    			  if (categories[pCat] == null) {
    				categories[pCat] = 0;
    			  }
    			  categories[pCat] += fc_json.products[p].quantity;
    			}
    			
    			for (var c in categories) {
    			  switch(c) {
    				case "other":
    				  if (country_code == "IE" && state_code == "D") {
    					shippingCost += 10;
    				  } else {
    					shippingCost += 20;
    				  }
    				  break;
    				default:
    				  if (country_code == "IE" && jQuery.inArray(state_name, validCounties) > -1) {
    					shippingCost += 5;
    				  } else {
    					shippingCost += 8.5;
    				  }
    			  }
    			}
    		 
      /* 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>
    
    <!-- REMOVE COUNTRY FLAG
    ==============================================-->
    
    <script type="text/javascript">
      FC.checkout.config.foxycomplete.flags = false;
    </script>
    
    
    [/code]
  • fc_adamfc_adam FoxyCart Team
    @intandem,

    Almost, but not quite.

    We won't be adding Northern Ireland as a state, but what I was suggesting was to change the language strings on the checkout so that for the UK country option, the only language string it matched against was "Northern Ireland". So while the customer would still technically be selecting the UK, they would only be able to search for Northern Ireland.

    To achieve that, you'd remove this line from your first code block:
    FC.locations.limitStatesTo("UK", "NI");
    

    And add this after your last code block: http://pastie.org/private/1k0gle3yhkbxeo0vmocfpa

    That last was taken from my other earlier post here: http://forum.foxycart.com/discussion/3323/ireland-incorrectly-requires-a-postcode#Item_11 and will both replace "United Kingdom" with "Northern Ireland" and also add in the required counties for Ireland.

    From what I understand, that should get you as close as we can currently to what you're after. Let me know if I've missed anything in your request and we can take another look.
  • Thanks, I hadn't seen that post yet. Will give this a go. Thanks!
  • intandemintandem Member
    edited October 2012
    Is this the correct syntax for limiting countries?:
    /* BEGIN CUSTOM LOCATION LOGIC */
     
            FC.locations.limitCountriesTo("IE","UK");
    		
    /* END CUSTOM LOCATION LOGIC */
    


    If I only use FC.locations.limitCountriesTo("IE"); it's fine and only shows Ireland (although it does not give me the county selector dropdown even though I've included your code for that), but with my above syntax, it still gives me the full drop-down of countries.

    I appreciate all your help and apologise that I still have to come back to you with this.

  • fc_adamfc_adam FoxyCart Team
    @intandem,

    Ah sorry, I didn't pick up on that, it would be:
    FC.locations.limitCountriesTo(["IE","UK"]);
    
  • Hi Adam

    I am beginning to dread writing back to you! However none of this is working at all. Here is my full code for the checkout template http://pastie.org/5117207, incl. Location Logic, Set County Codes, Shipping Logic and Remove Flags. As I am not familiar

    I have been using the given code snippets, hopefully in the correct order. However:

    1. The only country available to select is "Ireland"
    2. There is no drop-down of counties created.
    3. Hence, shipping costs are not being calculated.

    I am sure you'd like me to go away at this stage. As I mentioned before, I am completely willing to pay someone to correct the code for me. That really is not a problem. I just need to make it work. If this is all outside the domain of the support that Foxycart can reasonably can provide me with, perhaps you could point me in the direction of a programmer I can pay to fix it up? I don't want to get on your nerves but this is beyond anything I can figure out ... All I can tell is that the colour-coding in the code is not standard across all sections - does that mean something is breaking it somewhere?

  • fc_adamfc_adam FoxyCart Team
    @intandem,
    I am sure you'd like me to go away at this stage.

    Not at all - we're working towards pulling these types of customisations into the administration to make setting up this type of stuff much easier - so we understand it can be a bit hard at times.

    So a few issues that need fixing:

    This gets me every time, the UK's ISO code is actually GB:
    FC.locations.limitCountriesTo(["IE","GB"]);
    
    FC.locations.config.locations.GB.cn = "Northern Ireland";
    FC.locations.config.locations.GB.alt = [];
    

    Note I've removed a line from that last block to change the ISO 2 character code - as I just realised that could break some server-side validation.


    And finally, the following:
    if (country_code == "IE" && jQuery.inArray(state_name, validCounties) > -1) {
    

    Should be changed to:
    if (country_code == "IE" && state_code == "D") {
    

    That should cover the errors that are appearing currently.

    For your reference, I'll also whisper a list of some recommended developers you can work with in the future if you wish.
  • Hi Adam

    Fantastic news, it's all working now! I'm over the Moon! Thank you so much for all of your help! Foxycart at its best yet again! Had to fix one last thing because I had entered one of my categories in small letters instead of capitals, but all working perfectly now. Shall be eternally grateful - and I'm sure any other developers having to set up Irish shops will be very happy too with this solution. Gave you guys a Twitter shout out earlier :) And thanks for the list too.

  • fc_adamfc_adam FoxyCart Team
    @intandem,

    Awesome! Glad we got there!
Sign In or Register to comment.