1
votes

I have included following gem in my gem file gem 'spree_multi_currency', github: 'spree/spree_multi_currency', branch: '2-3-stable' in my application following currencies are already present: SGD,USD,EUR,AUD,GBP,PHP,THB,MYR and these are converting price properly. But my requirement is to add AED currency to so I have added that also SGD,USD,EUR,AUD,GBP,PHP,THB,MYR,AED from backendenter image description here

Now I automatically got this option in my header now when i click on AED it gives me following error

Started GET "/assets/world-globe.png" for 127.0.0.1 at 2016-01-26 10:26:08 +0100


Started POST "/currency/set" for 127.0.0.1 at 2016-01-26 10:26:11
+0100 Processing by Spree::CurrencyController#set as JSON   Parameters: {"currency"=>"AED"}   Spree::Country Load (1.1ms)  SELECT  "spree_countries".* FROM "spree_countries"  WHERE "spree_countries"."name" = 'N/A' LIMIT 1   Spree::User Load (1.2ms)  SELECT  "spree_users".* FROM "spree_users"  WHERE "spree_users"."id" = 1  ORDER BY "spree_users"."id" ASC LIMIT 1   Spree::Order Load (1.2ms) SELECT  "spree_orders".* FROM "spree_orders"  WHERE "spree_orders"."completed_at" IS NULL AND "spree_orders"."currency" = 'USD' AND "spree_orders"."guest_token" = 'ZtR5IUlQUC40ueZBlo21Pg' AND "spree_orders"."user_id" = 1 LIMIT 1   Spree::Adjustment Load (1.4ms)  SELECT "spree_adjustments".* FROM "spree_adjustments"  WHERE "spree_adjustments"."adjustable_type" = 'Spree::Order' AND "spree_adjustments"."adjustable_id" IN (6084)  ORDER BY spree_adjustments.created_at ASC   Spree::Order Load (0.9ms)  SELECT "spree_orders".* FROM "spree_orders"  WHERE "spree_orders"."user_id" = $1 AND "spree_orders"."completed_at" IS NULL AND (id != 6084)  [["user_id", 1]]    (0.9ms)  BEGIN   Spree::Order Exists (1.7ms)  SELECT  1 AS one FROM "spree_orders"  WHERE ("spree_orders"."number" = 'R501407003' AND "spree_orders"."id" != 6084) LIMIT 1   Spree::LineItem Load (1.3ms)  SELECT "spree_line_items".* FROM "spree_line_items"  WHERE "spree_line_items"."order_id" = $1 AND (currency != 'AED')  ORDER BY created_at ASC  [["order_id", 6084]]   Spree::Variant Load (1.3ms)  SELECT  "spree_variants".* FROM "spree_variants"  WHERE "spree_variants"."id" = $1 LIMIT 1  [["id", 2]]   Spree::Price Load (1.3ms)  SELECT  "spree_prices".* FROM "spree_prices"  WHERE "spree_prices"."deleted_at" IS NULL AND "spree_prices"."variant_id" = $1 AND "spree_prices"."currency" = 'AED' ORDER BY "spree_prices"."id" ASC LIMIT 1  [["variant_id", 2]]   Spree::Product Load (1.3ms)  SELECT  "spree_products".* FROM "spree_products"  WHERE "spree_products"."id" = $1 LIMIT 1  [["id", 2]]   Spree::Product::Translation Load (1.3ms)  SELECT "spree_product_translations".* FROM "spree_product_translations"  WHERE "spree_product_translations"."spree_product_id" = $1  [["spree_product_id", 2]]    (1.5ms)  ROLLBACK Completed 500 Internal Server Error in 56ms

RuntimeError - no AED price found for 28 Day Ultimate Teatox (28 Day): () Users/TopFormInvestment/.rvm/gems/ruby-2.1.4@skinnymint/bundler/gems/spree-cfe7e96539b6/core/app/models/spree/order/currency_updater.rb:34:in `update_line_item_price!'    () Users/TopFormInvestment/.rvm/gems/ruby-2.1.4@skinnymint/bundler/gems/spree-cfe7e96539b6/core/app/models/spree/order/currency_updater.rb:18:in `block in update_line_item_currencies!'

Please guide me how to solve this error. As I am new in spree

2

2 Answers

2
votes

Go to the Products in admin panel. There you can see the price tab, click the tab and then you change the prices there itself.

enter image description here

-1
votes

You did not set an AED price for the variant 28 Day Ultimate Teatox. In update_line_items_price! it has a local variable price which returns the variants price in the newly set currency. If the price isn't present it will raise the RuntimeError you are getting.

 def update_line_item_currencies!
    line_items.where('currency != ?', currency).each do |line_item|
      update_line_item_price!(line_item)
    end
  end

  # Returns the price object from given item
  def price_from_line_item(line_item)
    line_item.variant.prices.where(currency: currency).first
  end

  # Updates price from given line item
  def update_line_item_price!(line_item)
    price = price_from_line_item(line_item)

    if price
      line_item.update_attributes!(currency: price.currency, price: price.amount)
    else
      raise RuntimeError, "no #{currency} price found for #{line_item.product.name} (#{line_item.variant.sku})"
    end
  end