在Spree(RoR)中保存产品时价格乘以100

Mar*_*ark 4 ruby-on-rails spree ruby-on-rails-3.1

我在Rails 3.1.3和Ruby 1.9.3之上安装了在线购物框架Spree.我还使用Spree_i18n gem来本地化商店.现在,每当我保存产品时,价格都会乘以100.

例如,在管理区域中,我键入3.20的价格.这导致值320.如果我再次保存,它将更改为32000,依此类推.

这是我的本地化de_numbers.yml供参考:

---
de:
  number:
    currency:
      format:
        format: "%u%n"
        unit: "€"
        precision: 2
        separator: '.'
        delimiter: ','
Run Code Online (Sandbox Code Playgroud)

在我的设置中我无法想到任何异常,所以我想知道为什么这不是一个常见的问题.任何帮助将不胜感激.

Dom*_*edi 7

编辑:

spree-core:产品表单不处理与I18n /本地化相关的显示product.price和product.cost_price.要解决此问题,您需要修改核心.我将向Spree核心团队发布这个问题,但在此期间,我已经测试了这个修复程序,它应该可行.

/gems/spree_core-1.0.0/app/views/spree/admin/products/_form.html.erb中,您需要修改以下行:

<%= f.text_field :price, :value => number_with_precision(@product.price, :precision => 2) %>
Run Code Online (Sandbox Code Playgroud)

是这样的:

<%= 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')) %>
Run Code Online (Sandbox Code Playgroud)

还有这个:

<%= f.text_field :cost_price, :value => number_with_precision(@product.cost_price, :precision => 2) %>
Run Code Online (Sandbox Code Playgroud)

是这样的:

<%= 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')) %>
Run Code Online (Sandbox Code Playgroud)

从本质上讲,我们正在使它处理I18n潜在价值.

原版的:

我已经完全复制了您的文件,并尝试了一些测试来重新创建(创建新产品,新产品变体,更改产品价格,成本价格等).要重新创建它,您需要创建一个de_numbers.yml,并使用"config.default_locale ='de'"将您的本地化翻转为Spree初始化程序中的"de"

以下是一些建议的修复:

  1. 确保你运行bundle install
  2. 在您的Gemfile中,请确保您使用的是最新版本的i18n(

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

  1. 修复你的空白是2个空格,而不是标签(这可能是一个空白问题,它无法读取你的i18n值)
  2. 进入rails控制台,并注销值(即

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

  1. 尝试首先使用"en"语言环境,然后使用"de".
  2. 首先将您的值放入"de.yml"或"en.yml",并在放入"de_currency.yml"文件之前查看它们是否有效.