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.

<?php

namespace App\Http\Middleware;

use Aero\Common\Models\Currency;
use Aero\Store\Http\Middleware\EncryptCookies;

class SetFasciaCurrency
{
    public function handle($request, $next): void 
    {
        EncryptCookies::$exceptions[] = 'currency';

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

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

        return $next($request);
    }
}

 

Ensure the currency code exists in the currencies database table of the store.

 

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

<?php

namespace App\Providers;

use App\Http\Middleware\SetFasciaCurrency;
use Illuminate\Support\ServiceProvider;

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

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) {
        Store::setFasciaCurrency(Currency::find($currency));
    });
}

 

Additional considerations

  • The exchange-rate of the fascia currency is based on the store's default configuration currency.
  • If your store theme uses the Aero component system, the fascia currency will automatically be rendered for listings and products. However, if your theme utilises the range-slider component, you should ensure currency('[value]') and currency().fascia_exchange_rate are passed through as the formatter and multiplier attributes, respectively.
  • Any event which is queued and is an instance of Aero\Events\ManagedEvent will automatically handle re-applying the fascia currency when running from the queue worker. To force rendering the payment currency in mail notifications, use the .base modifier. For example: {{ order.total_price.base }}.

Articles in this section

Was this article helpful?
0 out of 0 found this helpful