add no-JS fallback for cart country selector
All checks were successful
deploy / deploy (push) Successful in 59s

The delivery country form now has action="/cart/country" with a
noscript submit button. Without JS, changing the country and clicking
Update POSTs to a new CartController.update_country action that saves
the country to session and redirects back to /cart.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-24 23:14:48 +00:00
parent 79764c7766
commit d0ea9d59f5
5 changed files with 64 additions and 1 deletions

View File

@@ -74,6 +74,19 @@ defmodule BerrypodWeb.CartController do
|> redirect(to: ~p"/cart")
end
@doc """
Updates delivery country via form POST (no-JS fallback).
"""
def update_country(conn, %{"country" => code}) when is_binary(code) and code != "" do
conn
|> put_session("country_code", code)
|> redirect(to: ~p"/cart")
end
def update_country(conn, _params) do
redirect(conn, to: ~p"/cart")
end
defp parse_quantity(str) when is_binary(str) do
case Integer.parse(str) do
{qty, _} when qty > 0 -> qty