Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove more usage of ItemAdjustments outside of OrderUpdater #1400

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,7 @@ def create_proposed_shipments

def apply_free_shipping_promotions
Spree::PromotionHandler::FreeShipping.new(self).activate
shipments.each { |shipment| ItemAdjustments.new(shipment).update }
updater.update_shipment_total
persist_totals
update!
end

# Clean shipments and make order back to address state
Expand Down
1 change: 0 additions & 1 deletion core/app/models/spree/order_contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def after_add_or_remove(line_item, options = {})
shipment = options[:shipment]
shipment.present? ? shipment.update_amounts : order.ensure_updated_shipments
PromotionHandler::Cart.new(order, line_item).activate
ItemAdjustments.new(line_item).update
reload_totals
line_item
end
Expand Down
12 changes: 4 additions & 8 deletions core/spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -591,16 +591,12 @@ def merge!(other_order, user = nil)

context "#apply_free_shipping_promotions" do
it "calls out to the FreeShipping promotion handler" do
shipment = double('Shipment')
allow(order).to receive_messages shipments: [shipment]
expect(Spree::PromotionHandler::FreeShipping).to receive(:new).and_return(handler = double)
expect(handler).to receive(:activate)
expect_any_instance_of(Spree::PromotionHandler::FreeShipping).to(
receive(:activate)
).and_call_original

expect(Spree::ItemAdjustments).to receive(:new).with(shipment).and_return(adjuster = double)
expect(adjuster).to receive(:update)
expect(order.updater).to receive(:update).and_call_original

expect(order.updater).to receive(:update_shipment_total)
expect(order.updater).to receive(:persist_totals)
order.apply_free_shipping_promotions
end
end
Expand Down