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

[Spree 2 Upgrade] WIP - Added adapted order.ship_method= #2669

Closed
Closed
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
12 changes: 12 additions & 0 deletions app/models/spree/order_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,18 @@ def pending_payments
payments.select {|p| p.state == "checkout"} # Original definition
end

# Although Spree 2 supports multi shipments per order, in OFN we keep the rule one shipment per order
# Thus, this method sets the given shipping_method on the first and only shipment in the order
def shipping_method=(shipping_method = nil)
if shipments.empty?
shipment = Spree::Shipment.new
shipment.order = self
shipment.save
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK we don't need this save as AR persists the order and all its associations when doing a order.save. Correct me if I'm wrong.

shipments << shipment
end
shipments.first.add_shipping_method(shipping_method, true)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we investigated how this works with the way Spree creates shipments in https://github.com/openfoodfoundation/spree/blob/fe0a1311abb097bf3ac8001a24246c6cff5ecdbb/core/app/models/spree/order.rb#L506-L515 ? That's the only place I know in Spree's codebase where shipments are created.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I have seen that code. I am closing this PR actually, we need to fix the specs and then we will see if this is still required.


private

def address_from_distributor
Expand Down