Commerce displaying country name instead of state on the final checkout screen (prior to payment)

Commerce displaying country name instead of state on the final checkout screen (prior to payment)

Hello,

Under certain conditions, Commerce fails to correctly display the correct state on the final payment screen prior to the checkout screen.  Instead, it will display whatever country is the nearest alphabetical match to the selected state.  For example, selecting Colorado results in Columbia being displayed instead.

This may only be affecting certain Commerce stores depending on whether or not multiple countries have been added, but I haven't bothered to check.

The problem appears to be with the javascript selectors not being specific enough.

Adding in the following selectors (in red) to the addNewShippingAddress(e) addNewBillingAddress(e) functions in the checkout-form-helper.js file as shown below corrects the problem:
  1. function addNewShippingAddress(e) {
  2.     var t = $D.getById(NEWLY_ADDED_SHIPPING_ADDRESS);
  3.     if (t && e) {
  4.         setInnerTextForId(NEWLY_ADDED_SHIPPING_ADDRESS_FULL_NAME, e.first_name + " " + e.last_name);
  5.         var n = new RegExp("\n","g")
  6.           , s = e.address.replace(n, " ");
  7.         if (setInnerHTMLForId(NEWLY_ADDED_SHIPPING_ADDRESS_PARTIAL_ADDRESS, s),
  8.         setInnerTextForId(NEWLY_ADDED_SHIPPING_ADDRESS_CITY, e.city),
  9.         e.state && "" != e.state) {
  10.             var r = e.state
  11.               , a = document.querySelector("[name='state'][value='" + r + "']");
  12.             (a = a || document.querySelector("[name='state'][data-value='" + r + "']")) && (r = a.innerText),
  13.             setInnerHTMLForId(NEWLY_ADDED_SHIPPING_ADDRESS_STATE, r + ", ")
  14.         } else
  15.             setInnerTextForId(NEWLY_ADDED_SHIPPING_ADDRESS_STATE, "");
  16.         setInnerTextForId(NEWLY_ADDED_SHIPPING_ADDRESS_POSTAL_CODE, e.postal_code);
  17.         var E = e.country
  18.           , i = document.querySelector("[name='country'][value='" + E + "']");
  19.         (i = i || document.querySelector("[name='country'][data-value='" + E + "']")) && (E = i.innerText),
  20.         setInnerTextForId(NEWLY_ADDED_SHIPPING_ADDRESS_COUNTRY, E),
  21.         setInnerTextForId(NEWLY_ADDED_SHIPPING_ADDRESS_TELEPHONE, e.telephone),
  22.         addClassInElement(t, THEME_CHECKOUT_LIST_SELECTED),
  23.         showElement(t)
  24.     }
  25. }
  26. function addNewBillingAddress(e) {
  27.     var t = $D.getById(NEWLY_ADDED_BILLING_ADDRESS);
  28.     if (t && e) {
  29.         setInnerTextForId(NEWLY_ADDED_BILLING_ADDRESS_FULL_NAME, e.first_name + " " + e.last_name);
  30.         var n = new RegExp("\n","g")
  31.           , s = e.address.replace(n, " ");
  32.         if (setInnerHTMLForId(NEWLY_ADDED_BILLING_ADDRESS_PARTIAL_ADDRESS, s),
  33.         setInnerTextForId(NEWLY_ADDED_BILLING_ADDRESS_CITY, e.city),
  34.         e.state && "" != e.state) {
  35.             var r = e.state
  36.               , a = document.querySelector("[name='state'][value='" + r + "']");
  37.             (a = a || document.querySelector("[name='state'][data-value='" + r + "']")) && (r = a.innerText),
  38.             setInnerHTMLForId(NEWLY_ADDED_BILLING_ADDRESS_STATE, r + ", ")
  39.         } else
  40.             setInnerTextForId(NEWLY_ADDED_BILLING_ADDRESS_STATE, "");
  41.         setInnerTextForId(NEWLY_ADDED_BILLING_ADDRESS_POSTAL_CODE, e.postal_code);
  42.         var E = e.country
  43.           , i = document.querySelector("[name='country'][value='" + E + "']");
  44.         (i = i || document.querySelector("[name='country'][data-value='" + E + "']")) && (E = i.innerText),
  45.         setInnerTextForId(NEWLY_ADDED_BILLING_ADDRESS_COUNTRY, E),
  46.         setInnerTextForId(NEWLY_ADDED_BILLING_ADDRESS_TELEPHONE, e.telephone),
  47.         addClassInElement(t, THEME_CHECKOUT_LIST_SELECTED),
  48.         showElement(t)
  49.     }
  50. }

Thanks,
Bryan