The price is multiplied by 100 when you save the product in Spree (RoR)

I installed the Spree online shopping platform on top of Rails 3.1.3 and Ruby 1.9.3. I also use Spree_i18n stone to localize the store. Now when I save the product, the price is multiplied by 100.

For example, in the administration area, I print the price of 3.20. This results in a value of 320. If I save again, it will change to 32000, etc.

Here is my localized de_numbers.yml for reference:

--- de: number: currency: format: format: "%u%n" unit: "€" precision: 2 separator: '.' delimiter: ',' 

I cannot come up with anything unusual in my installation, so I wonder why this is not a common problem. Any help would be appreciated.

+3
source share
2 answers

EDIT:

spree-core: The product form does not handle displaying product.price and product.cost_price in relation to I18n / localization. To fix this for you, you need to change the kernel. I'm going to post this on the Spree Core team, but in the interim I 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 change the following lines:

 <%= f.text_field :price, :value => number_with_precision(@product.price, :precision => 2) %> 

:

 <%= 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) %> 

:

 <%= 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 are creating potential I18n values ​​for it.

ORIGINAL:

I accurately reproduced your file and tried several tests to recreate this (create a new product, a new version of the product, change the price of the product, cost, etc.). To recreate this, you need to create de_numbers.yml and flip your localization as "de" in the Spree initializer using "config.default_locale = 'de"

Here are some suggested fixes:

  • make sure you run package installation
  • in your gemfile, make sure you are using the latest version of i18n (

gem 'spree_i18n' ,: git => 'git: //github.com/spree/spree_i18n.git')

  • fix blank space in 2 spaces instead of tabs (this is potentially a white space issue where it cannot read your i18n values )
  • Go to the rails console and log out (i.e.

I18n.t ('number.currency.format.unit')

  • Try to get this to work first "en" and then "de".
  • First add your values ​​to "de.yml" or "en.yml" and see if they work before inserting them into the file "de_currency.yml".
+6
source

I assume that you transfer the values ​​of your delimiters and delimiters. The setting looks right, so I think the price should be entered as

 3,20 

Instead

 3.20 

This discussion of currency formatting , while not specific to Ruby development, may provide additional information.

+1
source

Source: https://habr.com/ru/post/1400780/


All Articles