Jump to:

3448 Posts in 1062 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Currency, CurrencySymbol, CurrencyField, £, $, GBP - EXPLAINED!

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 776 Views
  • CHD
    Community Member
    218 Posts

    Currency, CurrencySymbol, CurrencyField, £, $, GBP - EXPLAINED! Link to this post

    So today I pulled my hair out for an hour trying to do somehting as simple as display £ signs in the CMS.
    I've had this issue before with the 2.x versions of SS (not sure if its sorted in 3?) and usually you have to hack the Currency.php file which has

    protected static $currencySymbol = '$';

    why this is hardcoded in I'll never understand.

    the problem is changing the $ to £ doesnt update the actual CMS fields, so you'll still see dollars all the time.
    I tried updating CurrencyField.php as that too has dollar signs hardcoded in

    function setValue($val) {
          $value = ($val) ? $val : 0.00;
          $this->value = '$' . number_format((double)preg_replace('/[^0-9.\-]/', '', $value), 2);

    So naturally I tried changing the $ to a £. which showed the "?" in the CMS as an unrecognised symbol.
    Changing it to £ just displayed the curreny as £50.00
    So I had to (In Dreamweaver) go to Modify>Page Properties>Title/Encoding and change to UTF-8.

    and that fixed it.

    I hate hackign core files, they'll only get overwritten at some point, but sometimes SS really seems to leave you no choice.

    Anyway, hopefully this helps.

  • CHD
    Community Member
    218 Posts

    Re: Currency, CurrencySymbol, CurrencyField, £, $, GBP - EXPLAINED! Link to this post

    P.S - You'll also find the fields will now throw up JS validation errors, because the stupid thing is hardcoded to look for $ signs, if there are none, it's not allowed.

    I checked regexpress for a GBP validator, but couldnt find one, so i've just ripped the JS validator function now as i'm simply too sick of this to carry on.

    I'm 100% sure that what I've done is a load of unnecessary crap, so PLEASE if somebody knows a simpler way to handle non $ currency/money in a basic SS install without the eCommerce module, let us all know!


  • Willr
    Forum Moderator
    5497 Posts

    Re: Currency, CurrencySymbol, CurrencyField, £, $, GBP - EXPLAINED! Link to this post

    Patches welcome! Obviously a legacy thing, no ones needed to update all the currencies framework wide (though sooner or later someone will!) Every reference throughout needs to be updated to use that variable you pointed out rather than hard coded string. There already exists a Currency::setCurrencySymbol(); function to override it globally but there doesn't appear to be a getter which is perhaps why it's not used. Raise it as a ticket (if it isn't already) on open.silverstripe.org and if you can list all the road blocks you're running that will help it get fixed for the next version.

  • merrick_sd
    Community Member
    95 Posts

    Re: Currency, CurrencySymbol, CurrencyField, £, $, GBP - EXPLAINED! Link to this post

    in my config.php i've set

    and on the front end this works

    However in my admin area its show a $

    public static $db = array(
    'Price' => 'Currency');

    public function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab('Root.Main', new CurrencyField("Price", "Price"));
    return $fields;


Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.