Skip to content

Commit ec987f7

Browse files
authored
Merge pull request #3150 from catchpoint/fix_update_billing
fix billing information update
2 parents 5d95f27 + 2b63262 commit ec987f7

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed

www/assets/js/country-list/country-list.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
((window) => {
44
class CountrySelector {
5-
constructor(selector, subdivisionSelector, isoCompliantJsonBlob) {
5+
constructor(selector, subdivisionSelector, isoCompliantJsonBlob, initialCountry, initialState) {
66
this.countryList = isoCompliantJsonBlob;
77
this.countries = Object.keys(this.countryList).map((code) => {
88
return {
@@ -22,9 +22,12 @@
2222

2323
this.countrySelector = selector;
2424
this.subdivisionSelector = subdivisionSelector;
25+
this.countrySelector.value = initialCountry;
2526

2627
// Fill in subdivisions
27-
this.fillSubdivision(this.countries[0].code);
28+
this.fillSubdivision(initialCountry ?? this.countries[0].code);
29+
30+
this.subdivisionSelector.value = initialState;
2831

2932
// Attach listener
3033
this.countrySelector.addEventListener("change", (e) => {
@@ -47,6 +50,7 @@
4750
}
4851

4952
fillSubdivision(countryCode) {
53+
this.subdivisionSelector.value = undefined;
5054
const divisions = this.getSubdivisions(countryCode);
5155
const opts = Object.keys(divisions).map((key) => {
5256
return new Option(divisions[key], key);
@@ -60,4 +64,4 @@
6064
}
6165

6266
window.CountrySelector = CountrySelector;
63-
})(window);
67+
})(window);

www/templates/account/billing/update-payment-confirm-address.php

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@
3131
<label for="state">State</label>
3232
<div>
3333
<select autocomplete="off" name="state" data-country-selector="state-selector" required>
34-
35-
<?php foreach ($state_list as $state) : ?>
36-
<option value="<?= $state['code'] ?>" <?php if ($state['code'] == $state_code) {
37-
echo 'selected';
38-
} ?>>
34+
<?php foreach ($state_list as $state): ?>
35+
<option value="<?= $state['code'] ?>">
3936
<?= $state['name']; ?>
4037
</option>
4138
<?php endforeach; ?>
@@ -45,21 +42,8 @@
4542
<div class="info-container country">
4643
<label for="country">Country</label>
4744
<select autocomplete="off" name="country" data-country-selector="selector" required>
48-
<?php foreach ($country_list as $country) : ?>
49-
<?php
50-
$current_code = $country["code"];
51-
$selected_country = false;
52-
if (isset($country_code) && !is_null($country_code)) {
53-
if ($current_code == $country_code) {
54-
$selected_country = true;
55-
}
56-
} else {
57-
if ($current_code == 'US') {
58-
$selected_country = true;
59-
}
60-
}
61-
?>
62-
<option value="<?= $country["code"] ?>" <?= $selected_country ? 'selected' : '' ?>>
45+
<?php foreach ($country_list as $country): ?>
46+
<option value="<?= $country["code"] ?>">
6347
<?= $country["name"]; ?>
6448
</option>
6549
<?php endforeach; ?>
@@ -83,18 +67,19 @@
8367
<script>
8468
(() => {
8569
const countryList = <?= $country_list_json_blob ?>;
70+
const initialCountry = "<?= $country_code ?>";
71+
const initialState = "<?= $state_code ?>";
8672
if (document.readyState === "loading") {
8773
document.addEventListener("DOMContentLoaded", () => {
8874
const countrySelectorEl = document.querySelector("[data-country-selector=selector]");
8975
const divisionSelectorEl = document.querySelector("[data-country-selector=state-selector]");
9076

91-
new CountrySelector(countrySelectorEl, divisionSelectorEl, countryList);
77+
new CountrySelector(countrySelectorEl, divisionSelectorEl, countryList, initialCountry, initialState);
9278
});
9379
} else {
9480
const countrySelectorEl = document.querySelector("[data-country-selector=selector]");
9581
const divisionSelectorEl = document.querySelector("[data-country-selector=state-selector]");
96-
97-
new CountrySelector(countrySelectorEl, divisionSelectorEl, countryList);
82+
new CountrySelector(countrySelectorEl, divisionSelectorEl, countryList, initialCountry, initialState);
9883
}
9984
})();
10085
</script>

0 commit comments

Comments
 (0)