-
-
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?
Changes from all commits
a7cde06
c73c2dd
7d62a7f
e548e74
cdcab7c
08ad2af
69abdca
c311b8a
851cccb
90eecc7
0315fc9
8db2445
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Orders | ||
class CheckStockService | ||
attr_reader :order | ||
|
||
def initialize(order:) | ||
@order = order | ||
end | ||
|
||
def sufficient_stock? | ||
@sufficient_stock ||= order.insufficient_stock_lines.blank? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that it was just copy and paste and broken before. |
||
end | ||
|
||
def update_line_items | ||
return [] if sufficient_stock? | ||
|
||
variants = [] | ||
order.insufficient_stock_lines.each do |line_item| | ||
order.contents.update_item(line_item, { quantity: line_item.variant.on_hand }) | ||
variants.push line_item.variant | ||
end | ||
|
||
variants | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,29 @@ | |
= render partial: "shopping_shared/order_cycles" | ||
|
||
%div{ "data-controller": "guest-checkout", "data-guest-checkout-distributor-value": @order.distributor.id } | ||
- if @any_out_of_stock | ||
= render ModalComponent.new(id: "out-of-stock-items", modal_class: "medium" ,instant: true, close_button: false) do | ||
- # please update app/assets/javascripts/templates/out_of_stock.html.haml if updating the modal html | ||
%a.close-reveal-modal{"data-action": "click->modal#close" } | ||
%i.ofn-i_009-close | ||
%h3 | ||
= t("js.out_of_stock.reduced_stock_available") | ||
%p | ||
= t("js.out_of_stock.out_of_stock_text") | ||
- @updated_variants.each do |variant| | ||
- if variant.on_hand == 0 | ||
%p | ||
%em | ||
= "#{variant.name_to_display} - #{variant.unit_to_display}" | ||
%span | ||
= t("js.out_of_stock.now_out_of_stock") | ||
- if variant.on_hand > 0 | ||
%p | ||
%em | ||
= "#{variant.name_to_display} - #{variant.unit_to_display}" | ||
%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 commentThe 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 |
||
|
||
%div{ style: "display: #{spree_current_user ? 'block' : 'none'}", "data-guest-checkout-target": "checkout" } | ||
= render partial: "checkout" | ||
|
||
|
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.
?