Question

I use spree_multi_currency gem https://github.com/pronix/spree-multi-currency in my spree application. It work but when I add product to cart that time it give error like

undefined method `target_shipment=' for #<Spree::Variant:0xb4ea7b80>

def add_to_line_item(line_item, variant, quantity, currency = nil, shipment = nil)
 if line_item
  line_item.target_shipment = shipment
  line_item.quantity += quantity.to_i
  line_item.currency = currency unless currency.nil?
 else
  .......
end

Here is my full trace

activemodel (4.0.2) lib/active_model/attribute_methods.rb:439:in `method_missing'
activerecord (4.0.2) lib/active_record/attribute_methods.rb:155:in `method_missing'
/home/tps/.rvm/gems/ruby-2.0.0-p247/bundler/gems/spree-multi-currency-0abaa72ab8ed/app/models/spree/order_decorator.rb:7:in `add_to_line_item'
/home/tps/.rvm/gems/ruby-2.0.0-p247/bundler/gems/spree-99a6ad9f0e4e/core/app/models/spree/order_contents.rb:10:in `add'
/home/tps/.rvm/gems/ruby-2.0.0-p247/bundler/gems/spree-99a6ad9f0e4e/core/app/models/spree/order_populator.rb:49:in `attempt_cart_add'
/home/tps/.rvm/gems/ruby-2.0.0-p247/bundler/gems/spree-99a6ad9f0e4e/core/app/models/spree/order_populator.rb:26:in `block in populate'
/home/tps/.rvm/gems/ruby-2.0.0-p247/bundler/gems/spree-99a6ad9f0e4e/core/app/models/spree/order_populator.rb:25:in `each'
/home/tps/.rvm/gems/ruby-2.0.0-p247/bundler/gems/spree-99a6ad9f0e4e/core/app/models/spree/order_populator.rb:25:in `populate'
/home/tps/.rvm/gems/ruby-2.0.0-p247/bundler/gems/spree-99a6ad9f0e4e/frontend/app/controllers/spree/orders_controller.rb:44:in `populate'
actionpack (4.0.2) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.2) lib/abstract_controller/base.rb:189:in `process_action'

Thanks in advance.

Was it helpful?

Solution

It looks like there's a mismatch between the method defined in the commit of Spree you're using and the method in spree_multi_currency.

Spree: add_to_line_item(variant, quantity, currency, shipment)

Spree_multi_currency: add_to_line_item(line_item, variant, quantity, currency = nil, shipment = nil)

Make sure you're using the correct branch of the extension to match your Spree branch.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top