Skip to content

Call empty only on unshipped orders#5418

Closed
nirnaeth wants to merge 2 commits intosolidusio:mainfrom
nirnaeth:empty_cart_error_with_shipped_order
Closed

Call empty only on unshipped orders#5418
nirnaeth wants to merge 2 commits intosolidusio:mainfrom
nirnaeth:empty_cart_error_with_shipped_order

Conversation

@nirnaeth
Copy link
Contributor

@nirnaeth nirnaeth commented Oct 4, 2023

Summary

Fixes #4438.

The change triggers @order.empty! only when the shipping status is false.
The 500 is not triggered from the FE, but only from the BE. Nevertheless I tested manually for both cases.

Notes:

  1. I was not able to redirect to the Shipping action (admin/order/xxxxxx/edit), directions are welcome.
  2. The test is failing on my local environment on interaction with the alert for confirming the emptying action. I am also not sure if that is the best location for the test itself. Please advise :)

Checklist

Code fails with a 500 on admin because of the order shipping status.
The change triggers @order.empty! only when the shipping status is false.
The test interacts with the headless browser, but manipulates the order
behind the scenes to simulate the shipping of the order in a second tab
@nirnaeth nirnaeth requested a review from a team as a code owner October 4, 2023 10:21
@github-actions github-actions bot added changelog:solidus_api Changes to the solidus_api gem changelog:solidus_backend Changes to the solidus_backend gem labels Oct 4, 2023
@kennyadsl
Copy link
Member

Thanks a lot, @nirnaeth! ❤️

Maybe unrelated to this fix: is emptying a completed order (whether it's shipped or not) something that could make sense in some scenarios? I can't figure out why someone would want to do that, so maybe we should just avoid it if the order is completed, instead of checking if it's shipped only.

cc @spaghetticode

@nirnaeth
Copy link
Contributor Author

nirnaeth commented Oct 6, 2023

by looking at the issue, I think this is more a case of an accident. You happen to have 2 tabs open and you complete the order in one. I don't think it's something really intentional.

happy to close the PR if you feel this is a non-problem or change the PR according to new specs :)

authorize! :update, @order, order_token
@order.empty!

@order.empty! unless @order.shipped?
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@order.empty! unless @order.shipped?
@order.empty! unless @order.completed?

Copy link
Member

Choose a reason for hiding this comment

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

@kennyadsl I think we currently allow emptying a complete order as long as it's not been shipped. I'm thinking it may make sense in some instances, but they're probably just corner cases, so we may prefer to change behavior and privilege what makes generally more sense.

@kennyadsl
Copy link
Member

@nirnaeth my comment was a bit twisted actually, this is what I meant: https://github.com/solidusio/solidus/pull/5418/files#r1348457754.

I don't think anyone wants to empty a completed order, as they don't want to empty a shipped order. Does it make sense?

@spaghetticode
Copy link
Member

@nirnaeth thanks for working on this! ❤️

I've checked out the code, now the API call succeeds with a 200 and the order is not emptied, so no 500 error anymore 🎉. Unfortunately, there's no error message shown and cart items disappear from the page, just as if it was emptied for real, so this may be confusing for users. For this reason, I'm thinking a more clear approach may be to fail with a 422 HTTP error and show an error message to the user, what do you think?

@nirnaeth
Copy link
Contributor Author

nirnaeth commented Oct 9, 2023

@nirnaeth my comment was a bit twisted actually, this is what I meant: https://github.com/solidusio/solidus/pull/5418/files#r1348457754.

I don't think anyone wants to empty a completed order, as they don't want to empty a shipped order. Does it make sense?

gotcha, let me see if the change you suggested fix both cases.

@nirnaeth
Copy link
Contributor Author

nirnaeth commented Oct 9, 2023

@nirnaeth thanks for working on this! ❤️

I've checked out the code, now the API call succeeds with a 200 and the order is not emptied, so no 500 error anymore 🎉. Unfortunately, there's no error message shown and cart items disappear from the page, just as if it was emptied for real, so this may be confusing for users. For this reason, I'm thinking a more clear approach may be to fail with a 422 HTTP error and show an error message to the user, what do you think?

makes perfect sense! mine was the minimum to get to the goal of not having a 500, but I do agree it makes more sense for UX to have a proper message explaining what's going on. let me see what I can do :)

@nvandoorn
Copy link
Contributor

Hey @nirnaeth thanks for the contribution. I pulled down your changes and made a few changes, and then pushed them back up here: https://github.com/nvandoorn/solidus/tree/empty_cart_error_with_shipped_order

Changes are as follows:

  1. Call order.incomplete? instead of order.shipped? as suggested by @kennyadsl
  2. Updated the new feature spec to make it pass.

You're welcome to pull my branch and push here, or I can open a new pull request if you would prefer.

@fthobe
Copy link
Contributor

fthobe commented Feb 7, 2025

@jarednorman merged in different PR and can be closed

@jarednorman jarednorman closed this Feb 8, 2025
@codecov
Copy link

codecov bot commented Feb 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.28%. Comparing base (51f44e1) to head (4a4bf62).
Report is 1807 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (51f44e1) and HEAD (4a4bf62). Click for more details.

HEAD has 3 uploads less than BASE
Flag BASE (51f44e1) HEAD (4a4bf62)
5 2
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5418       +/-   ##
===========================================
- Coverage   88.84%   70.28%   -18.56%     
===========================================
  Files         608      561       -47     
  Lines       14750    14301      -449     
===========================================
- Hits        13105    10052     -3053     
- Misses       1645     4249     +2604     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:solidus_api Changes to the solidus_api gem changelog:solidus_backend Changes to the solidus_backend gem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API] empty cart endpoint raises 500 error with shipped order

6 participants