Discussions

Can not manage to display currency symbol instead of code -or- can I just remove the currency portion of the price

I am pricing products in ILS - Israel Sheqel
Prices are appearing as ILS 12.34
instead of ₪ 12.34 (there is a symbol there, you may not be able to see it depending on your fonts/system)

The core code seems to support using the symbol, as it's described correctly in: commerce.currency.inc

'ILS' => array(
'code' => 'ILS',
'symbol' => '₪',
'name' => t('Israeli New Sheqel'),
'numeric_code' => '376',
'minor_unit' => t('Agora'),
'major_unit' => t('New Shekels'),
),

//the correct symbol is printed there in the 'symbol' line

Anyway, I can't figure out of the life of my why I can't get the symbol instead of the code.
If I change the currency to US dollars, I do get the $ dollar symbol instead of USD when prices are displayed.

Alternatively, if this is not possible, it would help to simply display the price as a number only without the code or symbol.

This might be an issue of a rare symbol that maybe isn't supported by some core php thing or something. You can see that I'm not a programmer.

Anyway, Drupal Commerce is very impressive and this is not a showstopper, just annoying because it's so pervasive.

Thanks for the great module!

Posted: May 18, 2012

Comments

Damien Tournoud on May 18, 2012

This might be an issue of a rare symbol that maybe isn't supported by some core php thing or something. You can see that I'm not a programmer.

Close :) We don't have a exhaustive database of symbol placement, so we decided to default to displaying the code for currencies we do not have direct knowledge of.

This is controlled by the 'symbol_placement' and 'code_placement' variables in the currency definition.

At this point, you have two options:

(1) Alter the currency definition only for your site.

Sticking something like this in a custom module should do the trick:

<?php
/**
 * Implements commerce_currency_info_alter().
 */
function [mymodule]_commerce_currency_info_alter(&$currencies) {
 
$currencies['ILS']['code_placement'] = '';
 
$currencies['ILS']['symbol_placement'] = 'after'; // Well, or 'before'.
}
?>

(2) Open an issue in the Drupal Commerce issue queue so that we change the currency definition for everyone.

photoboy on May 19, 2012

Both options are good, so I did both.

1) Made my first module ever, a great experience. And it worked!
2) Issue: http://drupal.org/node/1590142

But,
Consider the case of presenting price without a symbol or code...
Let's say I have a 3 column table, where each row is under the headers "Name" , "Price ($)", "Add to Cart"
In this sort of presentation, it's not necessary to put the currency symbol in every row. It should be possible to format the price without the symbol/code.
And it seems possible, as there are formatting options in Views (which is making this table) :
* Raw Amount
* Formatted Amount
* Formatted Amount with Components

Do these options come from Views or Commerce? If Commerce, I would make a feature request to have another option just like Raw, but with the decimal marker.

Thanks Damien!