-
-
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
Autoremove/update item from the cart if stock changed during checkout #13121
base: master
Are you sure you want to change the base?
Autoremove/update item from the cart if stock changed during checkout #13121
Conversation
Move sufficient_stock? to Orders::CheckStockService
Update line item if any related variant has run out of stock or has had stock reduced
It replicates the modal used by the cart : app/assets/javascripts/templates/out_of_stock.html.haml
We now check for insufficient stock when loading the checkout details or before updating the order.
There is no easy way to share template between AngularJS and Rails. The modal in `edit.html.haml` is a copy of app/assets/javascripts/templates/out_of_stock.html.haml, so we need to update both if either of them is updated.
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 work. All good and working but it would be good to tidy up a few little bits.
end | ||
|
||
def sufficient_stock? | ||
@sufficient_stock ||= order.insufficient_stock_lines.blank? |
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 kind of caching doesn't work with boolean values. If the result is false then it gets re-computed on every call. I think that you need to check for nil
.
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 it was just copy and paste and broken before.
= t("js.out_of_stock.now_out_of_stock") | ||
- if variant.on_hand > 0 | ||
%span | ||
= t("js.out_of_stock.only_n_remainging", num: variant.on_hand) |
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.
Typo? Oh no, the typo is in the translation files!
I would either add a comment # sic!
here, rename it or maybe start new lazy translations so that we can delete the old ones when we get rid of AngularJS.
@@ -152,6 +156,7 @@ def order_params | |||
# state. We need to do this when moving back to a previous checkout step, the update action takes | |||
# care of moving the order state forward. | |||
def update_order_state | |||
# debugger |
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.
?
What? Why?
When on the check out pages, update the order when an item becomes out of stock or an item stock is below the ordered quantity.
What should we test?
As guest or a logged in customer
--> you should see a modal telling you :
Repeat the above scenario when trying to :
You should be redirected to the "Details" step, and you should see an out of stock modal.
Release notes
Changelog Category (reviewers may add a label for the release notes):
The title of the pull request will be included in the release notes.