-
-
Notifications
You must be signed in to change notification settings - Fork 730
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
[split checkout] Fix bug preventing user from reaching payment step #10496
[split checkout] Fix bug preventing user from reaching payment step #10496
Conversation
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.
Hmm sounds like a tricky one. I agree, this seems like a hacky fix but it's not clear how else it could be fixed.
I was wondering if theres' any other way so jumped in to try.
I tried to clear the shipping address from the params (which I think the frontend JS should be doing), but the validation continues to execute and fail regardless
I discovered the temporary var Order#save_ship_address
, so I tried disabling this. I think this disabled some validation, but not all.
So I can't find a better way either, I give up, and approve this fix :)
@jibees as you're intimately familiar with split checkout, it would be great to get your feedback. |
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.
As @dacook already said, this may seem a bit hacky, but it does the job.
💪
Hey @rioug, Some preliminary comments:
I remember observing this behavior at some point, but the app has indeed changed quite a bit over time. This could be related with this code/PR, although I'm not sure this is still active - I'll need to double check. I'll proceed to test the workaround proposed in this PR. I'm not sure though, it is strictly correct to set the shipping to the billing address of the customer, for pick up methods. For example, for tax calculation, as we usually do this based on shipping address, with this tax setting:
I don't know how instances are set, but I assume this is the case for most -> something else for me to double check. Looking at the userguide:
So, this can lead to incorrect tax charges, in cases which the hub is located in another state (relevant for CA) or country with differing (business?) address. |
Ok I think I've found it now: openfoodnetwork/engines/order_management/app/services/order_management/order/updater.rb Lines 147 to 154 in 890ab67
And a spec here: openfoodnetwork/engines/order_management/spec/services/order_management/order/updater_spec.rb Lines 147 to 154 in 890ab67
I've deleted this code snippet and ran our system test on split checkout: Indeed some tests fail, because it uses So this seems to be the case for the legacy checkout - I did not test manually. But I guess we would need to decide whether we keep this behavior for split checkout or change it the proposal in this PR of
I'll pose the question on the #split-checkout channel. |
I feel like we should keep the same rule as legacy checkout as it looks like it has fixed the previous bug and never introduced side effects. But if there are strong opinions that we should move forward with the current proposal, I'm following. |
I agree on keeping the old behaviour and copying the distributor's address as shipping address. It's wrong to ship the delivery to the customer's home or business address when pickup is selected. The shipping address is also used for tax calculations and, while I'm no tax expert, I would expect the law of the store to be applied when picking up an order there and potentially paying in cash. This logic has worked for us so far. |
Thanks for the feedback, I'll rework my solution |
4f53599
to
6ab886a
Compare
openfoodnetwork/app/models/spree/order.rb Lines 341 to 365 in 890ab67
So I think my previous solution would have worked. Anyway I reworked the solution to use the distributor address for "pick up" shipping method. It introduces a little bit of duplication as I couldn't reuse existing code, but I believe the |
So it sounds like the fix here (whether the old or new solution) is simply just to get past validation. Then regardless, when the order is saved, it will copy the distributor. I wonder why this wasn't an issue with the old checkout process. The second fix seems ideal because it is in line with the |
I didn't think of that, I'll give it a try. My main issue was the |
@dacook So using openfoodnetwork/app/controllers/split_checkout_controller.rb Lines 141 to 151 in 5dd2737
as select_shipping_method returns early if there is no shipments :openfoodnetwork/app/models/concerns/order_shipment.rb Lines 39 to 50 in 5dd2737
|
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.
Thanks for looking into that. I have one more review sorry! I wonder if we can simplify a couple of bits.
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.
Great, thank you!
It would be good to squash the final solution down into one commit for the next reviewer.
When using a "pick up" shipping method, with a user who doesn't have a shipping address it was impossible to proceed to the payment step because shipping address was invalid. To fix this, we ensure that "ship_address_same_as_billing" parameter is set to true when using a "pick up" shipping method. use distributor address when shipping method doesn't require a ship address ; in doing this we follow the same logic as the legacy checkout
7573717
to
23c4298
Compare
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 squashed into one commit (hope this is fine).
Thanks for this one @rioug 🙏 This looks good to me!!
Managed to reproduce in master with the following scenario (thanks @rioug 🙏 ) :
With the PR this scenario is fixed: I can go to payment method screen with no error + if I go back I see shipping address has been correctly field up with distributor address. Marvelous 💪 |
@RachL Great! Thanks for testing this! This bug was a mystery in the beginning and we solved it in great team work! 💪 Just curious: When you jumped back to the 'step 1 - details', was there a pre-selected shipping method? I believe it should still have been Pick-up and no shipping address was shown, right? In your screenshot it's not active anymore, so you switched to 'home delivery'. And then the hub address was used as shipping address? Is this really what we want? You would want your own shipping address in that case, wouldn't you? |
Yes that's what happened, I've selected the delivery method after seeing pick-up was correctly saved because I was curious to see what the system saved as a shipping address.
Yes but in that particular case I've removed my shipping address from the form, I don't see how we can retrieve it. Let's see if this scenario happens in real life. For now cases that came up on production were cases where there was only a pick-up method and we have no idea how the user has end up with no shipping address... |
Hi! Some users don't have shipping address because normally if you don't select "Save shipping address", no shipping address should be saved. But there's a recent bug: even if you don't check the box, the shipping address is saved (and clears out the preceding one if there already was a saved one). The bug occurs each time a user with no shipping address selects a pickup method (even if the shop also has a shipping method). Steps to reproduce the prod scenario are here: #10479 (comment) |
When using a "pick up" shipping method, with a user who doesn't have a shipping address it was impossible to proceed to the payment step because shipping address was invalid.
To fix this, we ensure that "ship_address_same_as_billing" parameter is set to true when using a "pick up" shipping method.
What? Why?
In a very specific scenario, a user can be blocked from proceeding to the payment step on checkout :
It this case the user will get a shipping address error when clicking on "Next - Payment Method" button as the shipping address is invalid
I am not sure how a user can end up in this scenario, I didn't get to check the affected user. As far as I can see, there is no way to delete a user/customer shipping address. I managed to reproduce the error by manually delete the customer shipping address ( see the test section below )
I fixed the issue by setting
ship_address_same_as_billing
to true when the selected shipping method is a "pick up" one. It's a bit hacky but it seems like the easiest solution.Ideally we would skip validating the order's shipping address in this case, but that would mean getting rid of
accepts_nested_attributes_for :ship_address
inSpree::Order
which would probably cause other issue. I don't think there is a way to skip/conditionally skip validation withaccepts_nested_attributes_for
.Filipe did mention in this comment that
I don't if this correct or where in the code it's supposed to happen.
What should we test?
Create a new user
Place an order with the new user
Remove user shipping address via rails console x :
Load placed order:
o = Spree::Order.find_by number: 'R313071156'
Load customer
c = o.customer
, it should have aship_address_id
Remove ship_address,
Check in back office that address has been remove properly
Go to customer tab, choose shop you placed an order with , you should see "Edit" under "Shipping Address" for your use:
Start an order with the new user and go to checkout
Click on Next - Payment method -> you should be redirected to the payment step
Alternatively, you might be able to do the following, similar to what the system spec does, I ran out of time to test that :
Release notes
Changelog Category: User facing changes
The title of the pull request will be included in the release notes.