prevent checkout with unavailable product variants

- Include is_available flag in hydrated cart items
- Show unavailable message on cart items and product page
- Block add-to-cart for unavailable variants
- Redirect back to cart with error if checkout has unavailable items

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-03-13 13:34:22 +00:00
parent 09f55dfe67
commit a6e5db73c0
6 changed files with 49 additions and 10 deletions

View File

@@ -16,13 +16,20 @@ defmodule BerrypodWeb.CheckoutController do
cart_items = Cart.get_from_session(get_session(conn))
hydrated = Cart.hydrate(cart_items)
if hydrated == [] do
conn
|> put_flash(:error, "Your basket is empty")
|> redirect(to: ~p"/cart")
else
track_checkout_start(conn)
create_checkout(conn, hydrated)
cond do
hydrated == [] ->
conn
|> put_flash(:error, "Your basket is empty")
|> redirect(to: ~p"/cart")
Enum.any?(hydrated, &(&1.is_available == false)) ->
conn
|> put_flash(:error, "Some items in your basket are no longer available")
|> redirect(to: ~p"/cart")
true ->
track_checkout_start(conn)
create_checkout(conn, hydrated)
end
end
end