diff --git a/app/controllers/cart_controller.rb b/app/controllers/cart_controller.rb index d0efffe96c..30ee434695 100644 --- a/app/controllers/cart_controller.rb +++ b/app/controllers/cart_controller.rb @@ -9,7 +9,7 @@ class CartController < BaseController # costly Spree::Order#update!, which only needs to be run once. We avoid this by disabling # callbacks on Spree::Adjustment and then manually invoke Spree::Order#update! on success. Spree::Adjustment.without_callbacks do - cart_service = CartService.new(current_order(true), current_currency) + cart_service = CartService.new(current_order(true)) if cart_service.populate(params.slice(:products, :variants, :quantity), true) fire_event('spree.cart.add') diff --git a/app/services/cart_service.rb b/app/services/cart_service.rb index a997804eeb..a5e812c0d3 100644 --- a/app/services/cart_service.rb +++ b/app/services/cart_service.rb @@ -5,9 +5,9 @@ class CartService attr_reader :variants_h attr_reader :errors - def initialize(order, currency) + def initialize(order) @order = order - @currency = currency + @currency = order.currency @errors = ActiveModel::Errors.new(self) end diff --git a/spec/models/product_distribution_spec.rb b/spec/models/product_distribution_spec.rb index bf53b0b721..40ba536452 100644 --- a/spec/models/product_distribution_spec.rb +++ b/spec/models/product_distribution_spec.rb @@ -36,7 +36,7 @@ describe ProductDistribution do # When I add the product to the order, an adjustment should be made expect do - cart_service = CartService.new order, 'AU' + cart_service = CartService.new order cart_service.populate products: {product.id => product.master.id}, quantity: 1, distributor_id: distributor.id # Normally the controller would fire this event when the order's contents are changed diff --git a/spec/services/cart_service_spec.rb b/spec/services/cart_service_spec.rb index 3f0f4e0597..d3657bc809 100644 --- a/spec/services/cart_service_spec.rb +++ b/spec/services/cart_service_spec.rb @@ -6,13 +6,17 @@ describe CartService do let(:params) { {} } let(:distributor) { double(:distributor) } let(:order_cycle) { double(:order_cycle) } - let(:cart_service) { CartService.new(order, currency) } + let(:cart_service) { CartService.new(order) } + + before do + allow(order).to receive(:currency).and_return( currency ) + end context "end-to-end" do let(:order) { create(:order, distributor: distributor, order_cycle: order_cycle) } let(:distributor) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: [v]) } - let(:cart_service) { CartService.new(order, nil) } + let(:cart_service) { CartService.new(order) } let(:v) { create(:variant) } describe "populate" do diff --git a/spec/support/request/shop_workflow.rb b/spec/support/request/shop_workflow.rb index 5f3882da26..876f184644 100644 --- a/spec/support/request/shop_workflow.rb +++ b/spec/support/request/shop_workflow.rb @@ -17,7 +17,7 @@ module ShopWorkflow end def add_product_to_cart(order, product, quantity: 1) - cart_service = CartService.new(order, order.currency) + cart_service = CartService.new(order) cart_service.populate(variants: {product.variants.first.id => quantity}) # Recalculate fee totals