Skip to content

Commit

Permalink
Merge pull request #7299 from andrewpbrett/line-item-fees
Browse files Browse the repository at this point in the history
Update fees after changing a line item
  • Loading branch information
andrewpbrett authored Apr 8, 2021
2 parents 704ed12 + 5bfd6fd commit 9b3628a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/api/v0/shipments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def add
quantity = params[:quantity].to_i

@order.contents.add(variant, quantity, nil, @shipment)
@order.recreate_all_fees!

render json: @shipment, serializer: Api::ShipmentSerializer, status: :ok
end
Expand All @@ -78,6 +79,7 @@ def remove
quantity = params[:quantity].to_i

@order.contents.remove(variant, quantity, @shipment)
@order.recreate_all_fees!
@shipment.reload if @shipment.persisted?

render json: @shipment, serializer: Api::ShipmentSerializer, status: :ok
Expand Down
21 changes: 21 additions & 0 deletions spec/controllers/api/v0/shipments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,27 @@
expect(inventory_units_for(variant).size).to eq 2
expect(order.reload.line_items.last.price).to eq(variant_override.price)
end

context "when line items have fees" do
let(:fee_order) {
instance_double(Spree::Order, number: "123", distributor: variant.product.supplier)
}
let(:contents) { instance_double(Spree::OrderContents) }

before do
allow(Spree::Order).to receive(:find_by!) { fee_order }
allow(controller).to receive(:find_and_update_shipment) { }
allow(fee_order).to receive(:contents) { contents }
allow(contents).to receive(:add) { }
allow(fee_order).to receive(:recreate_all_fees!)
end

it "recalculates fees for the line item" do
params[:order_id] = fee_order.number
spree_put :add, params
expect(fee_order).to have_received(:recreate_all_fees!)
end
end
end

context '#remove' do
Expand Down

0 comments on commit 9b3628a

Please sign in to comment.