| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\Database\Migrations; |
| 4 |
|
| 5 |
use FluentCart\App\Models\Meta; |
| 6 |
use FluentCart\Framework\Support\Arr; |
| 7 |
|
| 8 |
class EuVatRegistrationMigrator |
| 9 |
{ |
| 10 |
public static function migrate() |
| 11 |
{ |
| 12 |
$settings = get_option('fluent_cart_tax_configuration_settings', []); |
| 13 |
$registrations = Arr::get($settings, 'eu_vat_settings.country_registrations', []); |
| 14 |
|
| 15 |
if (empty($registrations)) { |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
foreach ($registrations as $reg) { |
| 20 |
$country = strtoupper($reg['country'] ?? ''); |
| 21 |
if (!$country) { |
| 22 |
continue; |
| 23 |
} |
| 24 |
|
| 25 |
Meta::query()->updateOrCreate( |
| 26 |
['object_type' => 'eu_vat_registration', 'meta_key' => $country], |
| 27 |
['meta_value' => $reg, 'object_id' => 0] |
| 28 |
); |
| 29 |
} |
| 30 |
|
| 31 |
unset($settings['eu_vat_settings']['country_registrations']); |
| 32 |
update_option('fluent_cart_tax_configuration_settings', $settings, true); |
| 33 |
} |
| 34 |
} |
| 35 |
|