Help us understand the problem. What is going on with this article?

Prepare JPY amount in Spree Demo

More than 5 years have passed since last update.

Spree を日本語化するのは下記記事参考ですが…。
Rails製ECオープンソース「Spree」をRails4でインストール
最後が「日本の商品がないので、商品は表示されなくなった」ではチトさみしい。

というわけで、USD * 100 を JPY の値段にしちゃえ、とタスクを書きました。
lib/tasks/prepare_ja_demo.rake に置いて、次のコマンドを叩くと商品が表示されるようになります。

% rake prepare_ja_demo:usd_to_jpy
lib/tasks/prepare_ja_demo.rake
namespace :prepare_ja_demo do
  desc 'JPY が nil の variant に、USD * 100 を JPY として設定する'
  task usd_to_jpy: :environment do
    Spree::Variant.all.each do |v|
      jpy = v.prices.find_or_create_by(currency: 'JPY')
      next if jpy.amount
      print "#{v.sku} "
      jpy.amount = v.prices.where(currency: 'USD').first.amount * 100
      jpy.save!
    end

    puts ''
  end
end

実行結果

名称未設定.png
ダウンロード.png

maangie
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした