Skip to content
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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

rioug
Copy link
Collaborator

@rioug rioug commented Feb 4, 2025

⚠️ Please use clockify code #12476 Flower Farms ⚠️

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

  • Start an order and place a few items in the cart, with at one item with a quantity higher than 1
  • In the backoffice with a different session :
    • Set a product out of stock, ie: on_demand = false and on_hand = 0
    • For the item with a quantity higher than one, reduce stock below the quantity, is: on_demand = false, on_hand < item quantity
  • Back as a customer, proceed to check out :
    --> you should see a modal telling you :
    • One product is now out of stock
    • One product has only X remaining

Repeat the above scenario when trying to :

  • Move from Details to Payment step
  • Move from Payment to Confirmation step
    • Try with a paypal payment
    • Try with a stripe payment
  • Confirming an order

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):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

rioug added 12 commits February 4, 2025 15:39
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.
@rioug rioug added the user facing changes Thes pull requests affect the user experience label Feb 4, 2025
Copy link
Member

@mkllnk mkllnk left a 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?
Copy link
Member

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.

Copy link
Member

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)
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user facing changes Thes pull requests affect the user experience
Projects
Status: In Progress ⚙
Development

Successfully merging this pull request may close these issues.

Autoremove items from cart if they run out of stock during checkout
2 participants