Skip to content

Commit 7684899

Browse files
authored
Merge pull request #15 from daun/fix/persist-default-value
Fix empty iso when using USD
2 parents 35b024c + ae39d69 commit 7684899

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/Augmentables/AugmentedCurrency.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function formattedNoSymbol()
110110
*/
111111
public function iso(): string|null
112112
{
113-
return Arr::get($this->data->config, 'iso');
113+
return Arr::get($this->data->config, 'iso', Currencies::$fallbackCurrency);
114114
}
115115

116116
/**

src/Fieldtypes/CurrencyFieldtype.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected function configFieldItems(): array
102102
'display' => 'Currency',
103103
'instructions' => 'Select which currency you want to use for the field.',
104104
'type' => 'select',
105-
'default' => 'USD',
105+
'default' => Currencies::$fallbackCurrency,
106106
'options' => collect(Currencies::$currencyList)
107107
->map(fn($item, $key) => Arr::get($item, 'name') . " ($key)")
108108
->sortBy(fn($val) => $val),
@@ -168,7 +168,7 @@ public function augment($value)
168168
*/
169169
private function getIso(): string
170170
{
171-
return Arr::get($this->field()->config(), 'iso', 'USD');
171+
return Arr::get($this->field()->config(), 'iso', Currencies::$fallbackCurrency);
172172
}
173173

174174
private function convertToStorage($value)

src/Utils/Currencies.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
class Currencies
1010
{
11+
/**
12+
* The fallback currency to use when not specified.
13+
*/
14+
public static string $fallbackCurrency = "USD";
1115

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

0 commit comments

Comments
 (0)