Using Drupal 7 commerce_multicurrency with manual currency conversion

This is a note on how to implement the Drupal commerce_multicurrency module.

This recipe is for a site with two currencies, with manual currency conversion: we are going to manually add our prices in both currencies rather than using the European Central Bank conversion provided by commerce_multicurrency.

Users to the site may select which currency they wish to pay with, like this.

This slideshow requires JavaScript.

In my case, the default currency is GBP (British Pounds Sterling) and the additional currency is EUR (Euro).

Start with Drupal Commerce and its dependencies downloaded.

drush dl commerce
drush dl entity
drush dl rules
drush dl addressfield
drush dl views
drush dl ctools

I have enabled all of the commerce modules, and the dependencies as prompted.

Download and enable commerce_multicurrency.


Enable the required currencies.
I enabled EUR and GBP, removed USD.
I set GBP as default.

In my case I want to have manual, not automatic, currency conversion.

Commerce Multicurrency provides a Currency Handling tab.


I enabled a dedicated price field for Euro only.

(In my case the default price will be in British Pounds – I don’t need to enable a field to hold GBP prices – the default price field is enough).

Go to: admin/commerce/products/types
manage display so that the foreign currency field is hidden on the teaser and

Set up some products with product displays

Store > Products > Add

In Drupal Commerce, products do not display on the site automatically.

Add a content type called Product display. Add a Product Reference field to the content type.

On the manage display tab, hide the foreign currency field: we only want one field for price to be shown in the display. If you wish, add the Product reference field to the teaser – this will provide the Add to Cart button.

For each product, create a Product display node.

Enable shopping cart and currency selector blocks

I added Currency Selector and Shopping Cart to Sidebar first.

Create the Rule that will make the Currency Selector work

The Currency Selector block will set the site user’s currency preference.

In order to change the prices displayed when the user changes currency, we need to set up a Rule.

Import the following Rule:


{ "commerce_multicurrency_set_currency_price_eur" : {
"LABEL" : "Set the currency price to EUR",
"PLUGIN" : "reaction rule",
"WEIGHT" : "-9",
"REQUIRES" : [ "rules", "commerce_line_item", "commerce_product_reference" ],
"ON" : [ "commerce_product_calculate_sell_price" ],
"IF" : [
{ "data_is" : { "data" : [ "site:commerce-currency" ], "value" : "EUR" } },
{ "entity_has_field" : { "entity" : [ "commerce-line-item" ], "field" : "commerce_product" } },
{ "entity_has_field" : {
"entity" : [ "commerce-line-item:commerce-product" ],
"field" : "commerce_price_eur"
{ "NOT data_is_empty" : { "data" : [ "commerce-line-item:commerce-product:commerce-price-eur" ] } }
"DO" : [
{ "commerce_line_item_unit_price_amount" : {
"commerce_line_item" : [ "commerce-line-item" ],
"amount" : [ "commerce-line-item:commerce-product:commerce-price-eur:amount" ],
"component_name" : "base_price",
"round_mode" : "1"
{ "commerce_line_item_unit_price_currency_code" : {
"commerce_line_item" : [ "commerce_line_item" ],
"currency_code" : "EUR"

Cache pages for anonymous users

If your site caches pages for anonymous users (as it should: admin/config/development/performance) then you will experience a problem with the Select currency drop-down for anonymous users: you change it, but nothing happens – the currency remains the same.

I noticed the problem when I noticed the currency switcher not working for anonymous, but working fine when logged in.

The issue and a solution to it are discussed here:

Posted in drupal

Kasabi: NHS data

More fun with Kasabi and an update to my original post from the Open Government Hackday back in August 2011, and the subsequent Culture Hack day.

The NHS have published a lot of information in Open Data formats, and some of the datasets are available via Kasabi.

Because I love putting things on maps, I created a Kasabi API end-point which returns dentists in the London Borough of Lambeth.

This is the link to the kml generated by the Kasabi API:

Google Maps can consume KML data, so you can go to and paste the Kasabi API URL in to the search box, to see the data mapped.

(I had to try twice because first time Google Maps timed out while fetching the data. Subsequently it worked fine.)

This is the full link to the map.

Posted in kasabi, portfolio

British Council Activity Mapping

In 2010 I worked on a very interesting project for the British Council.

The brief was to help the external relations team communicate the work of the British Council throughout the UK. The result was the Activity Mapping Project.

One output of the project was a set of Google Earth animated presentations.

Maps were created for each parliamentary constituency in the UK.

The technical basis of this project was the processing of data from over 200 separate British Council teams. We asked each team to provide the address of the beneficiary organization, together with the overseas partner countries. I developed an ASP.Net MVC application to de-duplicate the address data, then we were in a position to geo-code the data to present on the maps.

Posted in British Council, maps, portfolio

The Drupal CMS – much more than ‘just’ code. Welcome to a community!

This is a talk given by Ben Wilding, Ed Crompton and me at the Brighton Drupal weekend, 15 September 2012.

It’s aimed at people relatively new to Drupal. We explain ways to get involved with the Drupal community, be productive and have fun!

The pdf for the talk is here:

WiP – presentation for Drupalcamp Brighton

Posted in drupal

How to make a field required in CiviCRM


Here’s an example from the hook_civicrm_buildForm() function in a custom module we’ve been working on.

if ($formName == ‘CRM_Contribute_Form_Contribution’) {
$form->addRule(‘receive_date’, ts(‘This field is required.’), ‘required’, NULL, NULL, NULL, TRUE);
$form->addRule(‘contribution_page_id’,¬† ts(‘This field is required.’), ‘required’, NULL, NULL, NULL, TRUE);

What does the TRUE at the end do?

It fixes the QuickForm “nonexistent html element” error, by forcing the rule to be applied, even if the target form element does not exist
So: try this first –

$form->addRule(‘receive_date’, ts(‘This field is required.’), ‘required’);

… and if you run into the nonexistent html element error, then add the extra parameters.

Posted in CiviCRM

Dance Europe

I’ve just completed a really interesting project for Dance Europe/Danza Europa – an international dance magazine.

It’s a bilingual site, in Spanish and English, with a Drupal Commerce store using multicurrency.

One thing I love about the site is that it showcases some amazing photography.

The Drupal Commerce store uses the following modules:

* Commerce Bulk Product Creation: this makes it easy for my client to add a new magazine to the store, and have the various product and price variations taken care of automatically.

* Commerce Multicurrency: helps with currency conversion for products (currency conversion can be either automated or manual), and provides a currency switcher block. More on how I implemented this module here.

* SagePay Form Integration for Drupal Commerce: thank you to i-kos for this. I contributed back to the module with some fixes for customers in the United States and Ireland.

Posted in drupal – a new OpenPublic website

Hello, here’s a report from the Made in Lambeth Good for Nothing event. A very creative crowd – designers, developers, artists – here at the Oasis Centre near Lambeth North station.

What’s Lambeth? It’s a London borough, located just to the south of central London.

View from the Oasis Centre. Image credit: Dan Burgess.

The story in a nutshell

In just 48 hours we’ve built the basics for a Lambeth co-op website: a new way for Lambeth people and the council to work together.

Here it is:

This was built in two days, standing on the shoulders of giants. We started out with the amazing OpenPublic Drupal distribution.

This gave us such a high-level starting point, allowing us to get going quickly and have everyone creating content. This is the power of open-source code re-use. Community documentation for OpenPublic is here.

Getting existing data from the Lambeth website

Richard Pope did some amazing work with ScraperWiki to get data from the existing Lambeth Council website. This got us started with some 600 or so pages which we imported into Drupal using the feeds module.

Try it out. Search for “school meals”. You know you want to!

Posted in drupal, portfolio

Drupal Commerce Kickstart version 2

I found this on Drupal Planet the other day:, so thought I’d give the new Drupal Commerce Kickstart distribution a try.

It looks really great, and quite inspiring for those starting out with a new e-commerce project. The theme is based on omega. Here are some screen-shots:

Posted in drupal

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘DATABASE.field_data_field_DELETED_FIELD’ doesn’t exist

Drupal 7 Error.

The scenario is: you deleted a field from one of your content types, but you later get this PDOException.

The error is saying that it can’t find a table with the name of the deleted field.

The solution is to go into mysql and remove the ‘ghost’ field entry from field_config and field_config_instance.
drush sql-cli
mysql> DELETE FROM field_config WHERE field_name = ‘field_DELETED_FIELD’;
mysql> DELETE FROM field_config_instance WHERE field_name = ‘field_DELETED_FIELD’;
drush cc all

(don’t forget to clear cache after deleting)

It seems that the existence of these ghost entries in field_config and field_config_instance is leading drupal to look for the field values (which it expects to find in Table ‘DATABASE.field_data_field_DELETED_FIELD’

With thanks to googletorp:
and bek:

Posted in drupal

Drupal 7 Views: link content to a file path

Let’s say we have a content type with a PDF file, and we want to link the body text of the node to the file.

In the view:
FORMAT: Show: Fields

Content: PDF file
Exclude from display: Checked
Formatter: URL to file

Content: Body
Rewrite the output of this field:
<a href=”[field_pdf_file]”>[body]</a>

Hope this helps.
Using the “URL to file” formatter is the key thing to remember.
PDF file will need to appear before the Body in the fields list (so that the [field_pdf_file] token is available to the Body).

Cross-posted from


Tagged with:
Posted in drupal