Currencies

How do I change the store currency?

In order to change the store currency we need to publish the store configuration file:

php artisan vendor:publish --tag aero::store-config

Then locate the configurations section of the published config/aero/store.php file and update the currency_code value of the active store configuration.

Ensure the new currency_code exists in the currencies database table of the store.

What is a fascia currency and how do I use it?

A fascia currency can be set to render a different currency to the one specified in the store configuration.

Setting the fascia currency

The easiest way to check for and apply the fascia currency is through store middleware.

The example snippet below details how to check for the presence of a currency cookie passed with the request:

class SetFasciaCurrency
{
    public function handle(\Illuminate\Http\Request $request, \Closure $next): void 
    {
        \Aero\Store\Http\Middleware\EncryptCookies::$exceptions[] = 'currency';

        if ($code = $request->cookie('currency')) {
            $currency = \Aero\Common\Models\Currency::find($code);

            $request->store()->setFasciaCurrency($currency);
        }

        return $next($request);
    }
}

The middleware class can then be pushed to the store middleware group within the register method of a service provider:

public function register(): void 
{  
    $this->app['router']->pushMiddlewareToGroup('store', SetFasciaCurrency::class);
}

Remember to call parent::register() if inside a module service provider.

If the fascia currency needs to be set when running a console command:

if ($this->app->runningInConsole() && ($currency = env('CURRENCY_CODE'))) {
    $this->app->booted(function () use ($currency) {
        \Aero\Store\Facades\Store::setFasciaCurrency(\Aero\Common\Models\Currency::find($currency));
    });
}

Additional Considerations