2

I’m creating a multi language site (Arabic/English) with Craft Commerce. On the Arabic cart page I output item.total with the help of

{{ item.total|commerceCurrency(cart.paymentCurrency, convert=true, format=true) }}

The price is output like so: "دولار أمريكي 5.00".

It translates $ to دولار أمريكي) دولار أمريكي = American dollar) and I want it to be output like so: "$5.00".

1 Answer 1

1

I don’t think it is possible to stop the filter to translate the $ symbol. I don’t know Arabic, but it seems weird to me that the filter does that. If you agree you could consider sending a feature request to Pixel and Tonic.

To work around the issue now you could set the format option to false and only use the commerceCurrency filter to convert the value. Then format it for the output manually with help of the number_format filter.

{% set total = item.total|commerceCurrency(cart.paymentCurrency, convert=true, format=false) %}

{% if cart.paymentCurrency.iso == 'usd' %}
    ${{ total|number_format(2, '.', ',') }}
{% elseif cart.paymentCurrency.iso == 'eur' %}
    {{ total|number_format(2, '.', ',') }} EUR
{% endif %}

Here is how you can apply the manual formatting to select currencies only.

{% if cart.paymentCurrency.iso == 'usd' %}
    {% set total = item.total|commerceCurrency(cart.paymentCurrency, convert=true, format=false) %}
    ${{ total|number_format(2, '.', ',') }}
{% elseif cart.paymentCurrency.iso == 'eur' %}
    {% set total = item.total|commerceCurrency(cart.paymentCurrency, convert=true, format=false) %}
    {{ total|number_format(2, '.', ',') }} EUR
{% else %}
    {{ item.total|commerceCurrency(cart.paymentCurrency, convert=true, format=true) }}
{% endif %}

It’s probably a good idea to use a Twig macro for this snippet.

2
  • Thanks Sir! But I am supposing if admin will add new payment currency then if condition will fail. I am trying to getting some dynamic solution. May 10, 2017 at 9:46
  • Updated the answer @MohitPrajapati
    – carlcs
    May 10, 2017 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.