-
-
Notifications
You must be signed in to change notification settings - Fork 729
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
2788 [Subscriptions] Fix address issues when syncing subscriptions and orders #3589
2788 [Subscriptions] Fix address issues when syncing subscriptions and orders #3589
Conversation
9933b7b
to
23cf072
Compare
app/models/order_updater.rb
Outdated
shipping_method = shipment.shipping_method | ||
next if shipping_method.require_ship_address | ||
return if order.shipment.andand.shipping_method.blank? | ||
return if order.shipment.shipping_method.require_ship_address |
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.
I was just discussing the use of andand in another PR with @mkllnk
maybe:
return if order.shipment.blank?
return if order.shipment.shipping_method.blank?
return if order.shipment.shipping_method.require_ship_address
or simply?
return if order.shipment.andand.shipping_method.andand.require_ship_address
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.
Or we implement the law of Demeter and then write:
return if order.require_ship_address?
😄
d96b302
to
3fc8e70
Compare
63da6da
to
eb1961c
Compare
fyi #3640 has been merged |
98f133f
to
b956b4e
Compare
Rebased and green, @luisramos0. Thanks. |
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.
nice 💪
I think update_associations_for can be simplified.
app/services/order_syncer.rb
Outdated
unless pickup_to_delivery && order.shipment.present? | ||
order.updater.__send__(:shipping_address_from_distributor) | ||
end | ||
|
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.
this is a bit brain damaging, isnt it? :-)
I didnt manage to improve it much but I think this looks a bit easier to follow:
pickup_to_delivery = force_ship_address_required?(order)
if !pickup_to_delivery || order.shipment.present?
update_ship_address_for(order) if (ship_address.changes.keys & relevant_address_attrs).any?
end
if !pickup_to_delivery || order.shipment.blank?
order.updater.__send__(:shipping_address_from_distributor)
end
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.
I'd extract this block above including the comment to a separate method, maybe into update_ship_address_for.
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.
I see that making this method public would mean touching another class but I think it's worth it.
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.
this is a bit brain damaging, isnt it? :-)
Yes, I had a difficult time following code paths for this. 😓
Thanks @luisramos0 and @mkllnk. I agree with your suggestions and have appended the commits. 🙂
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.
I'm pretty happy with this PR. I would like to know your opinion about public vs private before I approve though.
app/models/order_updater.rb
Outdated
|
||
order.ship_address = order.distributor.address | ||
end | ||
order.ship_address = order.__send__(: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.
Shouldn't we make that method public if we use it?
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.
yeah, address_from_distributor is also a candidate for a nice little service that could also help below in shipping_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.
I've made this method public as well. 🙂
app/services/order_syncer.rb
Outdated
unless pickup_to_delivery && order.shipment.present? | ||
order.updater.__send__(:shipping_address_from_distributor) | ||
end | ||
|
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.
I see that making this method public would mean touching another class but I think it's worth it.
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.
super!
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.
Nice!
I think this is the last subs v2 PR and it closes #2786 as well, correct @kristinalim ? |
@kristinalim so far in my tests my order bill address never gets updated when I edit the subscription bill address. Maybe I don't look at the right place? For instance:
What do you mean by This will create the order ? I used the order cycle closing time in order to create the order. Also where do you exactly see the order ship/bill address? I went to the "customer details" of the edit order submenu. But I guess it should show up some place else but I couldn't find where.... the invoice is showing the shipping address of my customer... Sorry if this is obvious :( |
I am unstaging this one from AUS to put the new test data there. this one can go next. |
this is now back to aus staging. |
This still achieves a logic issue before the Spree upgrade, where switching from pick-up to delivery affects whether simultaneous changes to shipping address are ignored or not. This behaviour can be fixed in a separate PR.
The way that the bill contact details and distributor address are set for pickup orders has changed. At this point, after before_save_hook is called, the bill contact details have already been set as well.
This method has become only a small part of the logic for updating the order's ship address. This no longer follows the method naming convention within OrderSyncer where update_*_for describes almost the complete logic for updating the association. This is renamed in preparation for extraction of the complete update logic for ship_address. The new method will be named update_ship_address_for.
5e8bdaa
to
1972606
Compare
Apologies, my comment on this is really late.
@RachL Immediately after creating a subscription, there are "orders" (proxy orders) listed under the subscription, but the real orders are not actually created until a background task that generates these is run. I checked just now and see that this is actually only 5 minutes (I don't have this running automatically in my local machine), so you can just wait 5 minutes too. If you don't want to wait, clicking the link to "edit the order" would create the order. The order needs to exist for the rest of the testing steps.
This screen recording shows where the subscription order's addresses should show up, @RachL. Are we looking at different places? I went through all the testing steps in my dev server and don't see a problem. I will also check the data you are using @RachL. Thank you! |
@kristinalim thank you for the tip! I didn't know the shortcut, but I was looking at the right place. It didn't worked last time, maybe something with staging it because now I could see each step more clearly! However 2 things that did not worked:
Updated testing notes: |
Sorry, my bad, Rachel! I was actually editing the non-address part of the subscription billing details (not address) here. So if you edit the subscription's billing name or phone number, it should be copied over to the orders' billing and shipping details. The address part would not be copied to the orders' shipping details because the order is pickup and would still use the hub's address. |
Thank you @kristinalim as #3782 is created I'm moving this PR foward! |
Fix shipping and billing address issues when syncing subscriptions and orders.
What? Why?
This fixes remaining issues in #2788, related to how changes to subscriptions' bill address, ship address, and shipping method are carried over to the orders.
This PR includes changes in PR #3560, and cherry-picks commits for v1 in #3605, so should not be merged until those have been approved and merged to their respective base branches.
It turned out that many spec assertions were passing only by accident in v1. See more info here: #3605 The specs had to be fixed in v1 so we could make sure to preserve the behaviour in v2. The fix specific to v2 is only in these commits:
What should we test?
Dependencies