mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Support setting country in API using country code
This commit is contained in:
parent
8ba71ce6ce
commit
cb533871ac
@ -149,6 +149,7 @@ class InvoiceApiController extends BaseAPIController
|
||||
'country_id',
|
||||
'private_notes',
|
||||
'currency_code',
|
||||
'country_code',
|
||||
] as $field) {
|
||||
if (isset($data[$field])) {
|
||||
$clientData[$field] = $data[$field];
|
||||
|
@ -106,6 +106,17 @@ class ClientRepository extends BaseRepository
|
||||
}
|
||||
}
|
||||
|
||||
// convert country code to id
|
||||
if (isset($data['country_code'])) {
|
||||
$countryCode = strtolower($data['country_code']);
|
||||
$country = Cache::get('countries')->filter(function ($item) use ($countryCode) {
|
||||
return strtolower($item->iso_3166_2) == $countryCode || strtolower($item->iso_3166_3) == $countryCode;
|
||||
})->first();
|
||||
if ($country) {
|
||||
$data['country_id'] = $country->id;
|
||||
}
|
||||
}
|
||||
|
||||
$client->fill($data);
|
||||
$client->save();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user