Align commerce module with the monorepo module structure by updating all namespaces to use the Core\Mod\Commerce convention. This change supports the recent monorepo separation and ensures consistency with other modules. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Core\Mod\Commerce\Console;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Core\Mod\Commerce\Services\CurrencyService;
|
|
|
|
/**
|
|
* Refresh exchange rates from configured provider.
|
|
*
|
|
* Should be scheduled to run periodically (e.g., hourly).
|
|
*/
|
|
class RefreshExchangeRates extends Command
|
|
{
|
|
protected $signature = 'commerce:refresh-exchange-rates
|
|
{--force : Force refresh even if rates are fresh}';
|
|
|
|
protected $description = 'Refresh exchange rates from the configured provider';
|
|
|
|
public function handle(CurrencyService $currencyService): int
|
|
{
|
|
$this->info('Refreshing exchange rates...');
|
|
|
|
$baseCurrency = $currencyService->getBaseCurrency();
|
|
$provider = config('commerce.currencies.exchange_rates.provider', 'ecb');
|
|
|
|
$this->line("Base currency: {$baseCurrency}");
|
|
$this->line("Provider: {$provider}");
|
|
|
|
// Check if rates need refresh
|
|
if (! $this->option('force') && ! \Core\Mod\Commerce\Models\ExchangeRate::needsRefresh()) {
|
|
$this->info('Rates are still fresh. Use --force to refresh anyway.');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$rates = $currencyService->refreshExchangeRates();
|
|
|
|
if (empty($rates)) {
|
|
$this->error('No rates were updated. Check logs for errors.');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
|
|
$this->info('Updated '.count($rates).' exchange rates:');
|
|
|
|
$rows = [];
|
|
foreach ($rates as $currency => $rate) {
|
|
$rows[] = [$baseCurrency, $currency, number_format($rate, 6)];
|
|
}
|
|
|
|
$this->table(['From', 'To', 'Rate'], $rows);
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|