Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the currency format for product prices within Spree

I'm upgrading spree to from spree 1.0 to 1.3 and get stuck with the new currency options.

I want to render prices as: '€ 100' but instead get '€100'. How do I get a space between the unit and the value?

Note: Changing the locale file doesn't work, since it uses the money gem.

like image 230
jewilmeer Avatar asked Oct 17 '13 14:10

jewilmeer


2 Answers

There are a bunch of ways to do this. The easiest would probably be to re-register the Euro currency with a different symbol.

Put the following in an initializer:

# encoding: utf-8
Money::Currency.register({
    :priority        => 1,
    :iso_code        => "EUR",
    :iso_numeric     => "978",
    :name            => "Euro",
    :symbol          => "€ ",
    :subunit         => "Cent",
    :subunit_to_unit => 100,
    :separator       => ".",
    :delimiter       => "," 
})

A rails console now reports:

> Spree::Money.new(100, currency: 'EUR')
=> € 100.00 
like image 66
gmacdougall Avatar answered Oct 31 '22 10:10

gmacdougall


I did the following in my config/initializers/spree.rb to inject a different symbol:

Money::Currency.table[:chf].merge!(symbol: 'CHF ')

This way the currencies aren't going to mix up.

like image 26
schmijos Avatar answered Oct 31 '22 12:10

schmijos