Skip to content

Commit

Permalink
Merge pull request #15 from daun/fix/persist-default-value
Browse files Browse the repository at this point in the history
Fix empty iso when using USD
  • Loading branch information
doefom authored Aug 19, 2024
2 parents 35b024c + ae39d69 commit 7684899
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Augmentables/AugmentedCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function formattedNoSymbol()
*/
public function iso(): string|null
{
return Arr::get($this->data->config, 'iso');
return Arr::get($this->data->config, 'iso', Currencies::$fallbackCurrency);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Fieldtypes/CurrencyFieldtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function configFieldItems(): array
'display' => 'Currency',
'instructions' => 'Select which currency you want to use for the field.',
'type' => 'select',
'default' => 'USD',
'default' => Currencies::$fallbackCurrency,
'options' => collect(Currencies::$currencyList)
->map(fn($item, $key) => Arr::get($item, 'name') . " ($key)")
->sortBy(fn($val) => $val),
Expand Down Expand Up @@ -168,7 +168,7 @@ public function augment($value)
*/
private function getIso(): string
{
return Arr::get($this->field()->config(), 'iso', 'USD');
return Arr::get($this->field()->config(), 'iso', Currencies::$fallbackCurrency);
}

private function convertToStorage($value)
Expand Down
4 changes: 4 additions & 0 deletions src/Utils/Currencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

class Currencies
{
/**
* The fallback currency to use when not specified.
*/
public static string $fallbackCurrency = "USD";

/**
* Get the currency details by its ISO identifier ("EUR", "USD", etc.).
Expand Down

0 comments on commit 7684899

Please sign in to comment.