5-Minute Quickstart
This quickstart follows the Aegean Voyages (aegeanvoyages.example) charter pricing examples in site/modules/Currency/examples/real-world/.
-
Sync official exchange rates via CLI
Fetch the latest European Central Bank rates (or preview with
--dry-runfirst):Terminal window php vendor/bin/wire currency:sync --provider=ecb --dry-run --jsonphp vendor/bin/wire currency:sync --provider=ecb --json -
Calculate exact charter totals and deposit splits
<?php namespace ProcessWire;use Totoglu\Currency\Domain\RoundingMode;use Totoglu\Currency\Value\Money;$currency = Currency::requireInstance($wire);// Build Money from major string (never float)$baseCharter = Money::fromMajor('14700.00', 'EUR');$apa = $baseCharter->percentage('30', RoundingMode::HalfUp);$totalEur = $baseCharter->add($apa);// Split 30% deposit and 70% balance with zero cent loss[$depositEur, $balanceEur] = $totalEur->allocate([30, 70]); -
Convert to the visitor’s active currency
<?php namespace ProcessWire;$activeCode = $currency->activeCurrency(); // defaults to base currency (EUR)$conversion = $currency->convert($totalEur, $activeCode, date: null, applySpread: true);echo $currency->format($conversion->converted, 'en_US', ['show_code' => true]); -
Allow visitors to switch currencies safely
<?php namespace ProcessWire;$allowed = $currency->resolveAllowedCurrencies(['EUR', 'USD', 'GBP', 'TRY']);$options = $currency->currencyOptions($allowed);if ($input->requestMethod('POST') && $input->post->text('currency_code')) {$session->CSRF->validate();$currency->setActiveCurrency($input->post->text('currency_code'));} -
Verify in Setup -> Currencies
Open Setup -> Currencies -> Overview to test spot and historical conversions in the Live Currency Converter, or inspect Rate History to audit locked daily snapshots.