From d1916725c56cc53209825f9c07cd8fcc0efa9e1c Mon Sep 17 00:00:00 2001 From: tonis Date: Fri, 29 Sep 2023 13:52:00 +0300 Subject: [PATCH] fixed setting counrty correctly --- src/AddressForm.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/AddressForm.php b/src/AddressForm.php index 67bb8e7..a841b9d 100644 --- a/src/AddressForm.php +++ b/src/AddressForm.php @@ -133,6 +133,7 @@ public function getCountries() : array private function setDefaults() { + if (empty($this->address)) { $params = []; if (!empty($this->disabledFields)) { @@ -146,11 +147,17 @@ private function setDefaults() $this->country = country($this->allowedCountries[0]); $this->address->country = $this->country->getIsoAlpha2(); } - if(!empty($this->defaultCountry)) { - if(!in_array($this->defaultCountry, $this->allowedCountries) && !empty($this->allowedCountries)) { - throw new ErrorException("the set defaultCounty '{$this->defaultCountry}' must be one of the configured allowedCountries"); - } - $this->country = country($this->defaultCountry); + + + if(!empty($this->address->country)){ + $this->country = country($this->address->country); + } + + if(empty($this->address->country) && !empty($this->defaultCountry)) { + if(!in_array($this->defaultCountry, $this->allowedCountries) && !empty($this->allowedCountries)) { + throw new ErrorException("the set defaultCounty '{$this->defaultCountry}' must be one of the configured allowedCountries"); + } + $this->country = country($this->defaultCountry); } if (empty($this->submitText)) {