mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add basic out of stock modal
This commit is contained in:
@@ -11,11 +11,12 @@ module OrderStockCheck
|
||||
end
|
||||
|
||||
def handle_insufficient_stock
|
||||
stock_service = Orders::CheckStockService.new(@order)
|
||||
@any_out_of_stock = false
|
||||
|
||||
stock_service = Orders::CheckStockService.new(order: @order)
|
||||
return if stock_service.sufficient_stock?
|
||||
|
||||
flash[:error] = Spree.t(:inventory_error_flash_for_insufficient_quantity)
|
||||
redirect_to main_app.cart_path
|
||||
@any_out_of_stock = true
|
||||
end
|
||||
|
||||
def check_order_cycle_expiry
|
||||
|
||||
@@ -20,6 +20,11 @@
|
||||
= render partial: "shopping_shared/order_cycles"
|
||||
|
||||
%div{ "data-controller": "guest-checkout", "data-guest-checkout-distributor-value": @order.distributor.id }
|
||||
= #TODO create new component ? reuse out_of_stock.html.haml template
|
||||
- if @any_out_of_stock
|
||||
= render ModalComponent.new(id: "out-of-stock-items", instant: true) do
|
||||
%div
|
||||
Some items are out of stock
|
||||
%div{ style: "display: #{spree_current_user ? 'block' : 'none'}", "data-guest-checkout-target": "checkout" }
|
||||
= render partial: "checkout"
|
||||
|
||||
|
||||
@@ -66,12 +66,4 @@ module CheckoutHelper
|
||||
click_on "Complete order"
|
||||
expect(page).to have_content "Back To Store"
|
||||
end
|
||||
|
||||
def out_of_stock_check(step)
|
||||
visit checkout_step_path(step)
|
||||
|
||||
expect(page).not_to have_selector 'closing', text: "Checkout now"
|
||||
expect(page).to have_selector 'closing', text: "Your shopping cart"
|
||||
expect(page).to have_content "An item in your cart has become unavailable"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -88,21 +88,6 @@ RSpec.describe "As a consumer, I want to checkout my order" do
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples "when I have an out of stock product in my cart" do
|
||||
before do
|
||||
variant.update!(on_demand: false, on_hand: 0)
|
||||
end
|
||||
|
||||
it "returns me to the cart with an error message" do
|
||||
visit checkout_path
|
||||
|
||||
expect(page).not_to have_selector 'closing', text: "Checkout now"
|
||||
expect(page).to have_selector 'closing', text: "Your shopping cart"
|
||||
expect(page).to have_content "An item in your cart has become unavailable"
|
||||
expect(page).to have_content "Update"
|
||||
end
|
||||
end
|
||||
|
||||
context "as a guest user" do
|
||||
before do
|
||||
visit checkout_path
|
||||
@@ -222,8 +207,6 @@ RSpec.describe "As a consumer, I want to checkout my order" do
|
||||
"Local", "Shipping with Fee", "Z Free Shipping without required address"
|
||||
]
|
||||
end
|
||||
|
||||
it_behaves_like "when I have an out of stock product in my cart"
|
||||
end
|
||||
|
||||
context "on the 'payment' step" do
|
||||
@@ -235,8 +218,6 @@ RSpec.describe "As a consumer, I want to checkout my order" do
|
||||
it "should allow visit '/checkout/payment'" do
|
||||
expect(page).to have_current_path("/checkout/payment")
|
||||
end
|
||||
|
||||
it_behaves_like "when I have an out of stock product in my cart"
|
||||
end
|
||||
|
||||
describe "hidding a shipping method" do
|
||||
@@ -305,8 +286,14 @@ RSpec.describe "As a consumer, I want to checkout my order" do
|
||||
login_as(user)
|
||||
end
|
||||
end
|
||||
it "returns me to the cart with an error message" do
|
||||
out_of_stock_check(step)
|
||||
|
||||
it "displays a modal warning the user of updated cart" do
|
||||
visit checkout_step_path(step)
|
||||
|
||||
expect(page).to have_selector 'closing', text: "Checkout now"
|
||||
within "#out-of-stock-items" do
|
||||
expect(page).to have_content "Some items are out of stock"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user