Let's face it, the internet doesn't just sell to our neighbors down the street, it can literally connect you to the whole world. Last we checked, there are hundreds of currencies and thousands of countries. It's hard to address them all. We've provided the framework for simplified currency conversion in Drupal Commerce core. But we've also built a framework that has already enabled lots of solutions to popup on drupal.org as free currency conversion solutions.
In the next section we outline how one might convert currencies using only Drupal Commerce, but we admit plainly that this has a very limited use-case. The exercise is intended to teach you how to deal with the pricing rules that every major ecommerce shop is going to use. Directly below, we've listed a few other options you have available to meet your currency conversion requirements:
Enable Multiple Currencies
Before you can make a single rule or product into a different currency, you will need to enable a few of the currencies on the backend. Below we show you how to do that.
Multiple Currencies
Just like if you were translating content, you have to enable multiple currencies before you can convert them. To get started, you must navigate to the Store Configuration screen and click Currency Settings.
- Administration
- Store
- Configure
Currency Settings
Here on the currency settings page, all you can really do is enable currencies and set the default currency.
- Administration
- Store
- Configure
- Currency Settings
Edit Product
You can then select which currency you want for your product.
- Administration
- Store
- Products
- Edit Product
Multiple Currencies
When you've got currencies enabled you can do all sorts of interesting things with prices.
Static Currency Exchange Rate
Converting from one currency to another is possible through Rules. We
recommend using only core for this if you want the conversion rate to be input
as a static variable. For example, you simply want to say that 1 US dollar is
equal to .76 Euros, that would be a fine and relatively easy thing to produce
using rules.
Below we work through an entire exercise where we use Rules to create such a
scenario as mentioned above.
Original Pricing
The original pricing is shown here for three products. Our goal is to
create a rule that affects the prices and changes the currency. Note
that you need to enable a few other currencies to make this work.
- Administration
- Store
- View Products
Product Pricing Rules
The first step is to click on Store and then "Configuration" and,
finally, Product Pricing Rules. That is where the magic all happens when
dealing with currency exchange.
- Administration
- Store
- Product Pricing Rules
Pricing Rule
We need to click on add a pricing rule. If this is your first time on
this screen, maybe navigate around and look at how some of these other
rules are setup. If this is your first time dealing with Rules, we
highly recommend additional
tutorials.
- Administration
- Store
- Product Pricing Rules
- Click Add a Price
Name Rule
After you have created a name, click "Add Condition."
- Administration
- Store
- Product Pricing Rules
- Name Rule
- Click Add Condition
Data Comparison
After clicking "Add Condition…"
You will want to choose "Data Comparison" and then select
"commerce-line-item:commerce-unit-price:currency-code
" using the object
navigator.
- Administration
- Store
- Product Pricing Rules
- Edit Rule
- Click Add Condition
- Choose "Data Comparison"
Currency to Filter
Note that we are creating a filter that will only allow US dollars
into our actions. Without this filter, all line items would go through
this rule.
- Administration
- Store
- Product Pricing Rules
- Click Add Condition
- Choose Which Currency to Act On
Convert Numbers
Click "Add Action"
In order to actually create a currency conversion we need to do a
little math. This next step is where you add the currency exchange
rate.
- Administration
- Store
- Product Pricing Rules
- Click Add Action
- Select Multiply
Doing the Exchange
If you had 1 US dollar, how much would that equal in your other
currency? It changes, but for our exercise we're going to assume a
static number works for us. (Dynamic currency conversion is possible
with Commerce
Multicurrency).
- Administration
- Store
- Product Pricing Rules
- Click Add Action
- Select Multiply
- Multiply by 0.76
Convert Currency Symbol
Click Add Action.
Select "Convert the unit price to a different currency" so that we
can actually convert the currency from US dollars to a new currency.
This exchange is only going to change the currency symbol, it will not
actually tweak the numbers.
- Administration
- Store
- Product Pricing Rules
- Click Add Action
Final Currency
We are simply selecting the final currency symbol. You can safely
ignore the data selector.
- Administration
- Store
- Product Pricing Rules
- Click Add Action
- Select Currency Symbol
Final Screen
The final screen for the rule. If your screen doesn't look like this, go
through the steps above carefully.
- Administration
- Store
- Product Pricing Rules
- Review Custom Rule
Example Cart
We have not modified any of the products prices, but we have
successfully converted all of the currency to Euros and exchanged the
prices. For example, Product Three is listed as $32 US dollars in the database, but is listed here as 7,60 Euros.