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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user