I installed the online shopping framework Spree on top of Rails 3.1.3 and Ruby 1.9.3. I also use the Spree_i18n gem to localize the shop. Now, whenever I save a product, the price is multiplied by 100.
For example, in the admin area, I type the price 3.20. That results in the value 320. If I save again, it changes to 32000 and so on.
Here is my localized de_numbers.yml for reference:
---
de:
number:
currency:
format:
format: "%u%n"
unit: "€"
precision: 2
separator: '.'
delimiter: ','
I can not think of anything unusual in my setup so I wonder why this is not a common problem. Any help will be appreciated.
EDIT:
spree-core: the Product form is not handling displaying product.price and product.cost_price with regards to I18n / localization. To fix this to work for you, you'll need to modify the core. I'm going to post to the Spree Core team about this, but in the interim, I've tested this fix and it should work.
In /gems/spree_core-1.0.0/app/views/spree/admin/products/_form.html.erb, you will need to modify these lines:
<%= f.text_field :price, :value => number_with_precision(@product.price, :precision => 2) %>
to be this:
<%= f.text_field :price, :value => number_with_precision(@product.price, :precision => I18n.t('number.currency.format.precision'), :separator => I18n.t('number.currency.format.separator'), :delimiter => I18n.t('number.currency.format.delimiter')) %>
and this:
<%= f.text_field :cost_price, :value => number_with_precision(@product.cost_price, :precision => 2) %>
to be this:
<%= f.text_field :cost_price, :value => number_with_precision(@product.cost_price, :precision => I18n.t('number.currency.format.precision'), :separator => I18n.t('number.currency.format.separator'), :delimiter => I18n.t('number.currency.format.delimiter')) %>
Essentially, we're making it handle I18n potential values.
ORIGINAL:
I've duplicated your file exactly, and tried a few tests to recreate this (create a new product, new product variant, change the product price, cost price, etc.). To re-create this, you need to create a de_numbers.yml, and flip your localization to be 'de' in the Spree initializer with "config.default_locale = 'de'"
Here are some suggested fixes:
gem 'spree_i18n', :git => 'git://github.com/spree/spree_i18n.git')
I18n.t('number.currency.format.unit')
I'm guessing you've transposed the meanings of your separator and delimiter characters. The setup looks correct, so my thinking is that the price needs to be entered as
3,20
Rather than
3.20
This discussion of currency formatting, although not specific to Ruby development, may provide additional insight.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With