-
-
Notifications
You must be signed in to change notification settings - Fork 725
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
shipments << shipment | ||
end | ||
shipments.first.add_shipping_method(shipping_method, true) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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.