Skip to content

Commit

Permalink
fixed setting counrty correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
TonisOrmisson committed Sep 29, 2023
1 parent 628ddd5 commit d191672
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/AddressForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public function getCountries() : array

private function setDefaults()
{

if (empty($this->address)) {
$params = [];
if (!empty($this->disabledFields)) {
Expand All @@ -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)) {
Expand Down

0 comments on commit d191672

Please sign in to comment.