integrate R module and add url editor ui
Replaces hardcoded paths with R module throughout: - Shop components: layout nav, cart, product links - Controllers: cart, checkout, contact, seo, order lookup - Shop pages: collection, product, search, checkout success, etc. - Site context: nav item url resolution Admin URL management: - Settings page: prefix editor with validation feedback - Page renderer: url_editor component for page URLs - CSS for url editor styling Test updates for cache isolation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -41,13 +41,13 @@ defmodule BerrypodWeb.CartController do
|
||||
conn
|
||||
|> Cart.put_in_session(cart)
|
||||
|> put_flash(:info, "Added to basket")
|
||||
|> redirect(to: ~p"/cart")
|
||||
|> redirect(to: R.cart())
|
||||
end
|
||||
|
||||
def add(conn, _params) do
|
||||
conn
|
||||
|> put_flash(:error, "Could not add item to basket")
|
||||
|> redirect(to: ~p"/cart")
|
||||
|> redirect(to: R.cart())
|
||||
end
|
||||
|
||||
@doc """
|
||||
@@ -60,7 +60,7 @@ defmodule BerrypodWeb.CartController do
|
||||
conn
|
||||
|> Cart.put_in_session(cart)
|
||||
|> put_flash(:info, "Removed from basket")
|
||||
|> redirect(to: ~p"/cart")
|
||||
|> redirect(to: R.cart())
|
||||
end
|
||||
|
||||
@doc """
|
||||
@@ -73,7 +73,7 @@ defmodule BerrypodWeb.CartController do
|
||||
|
||||
conn
|
||||
|> Cart.put_in_session(cart)
|
||||
|> redirect(to: ~p"/cart")
|
||||
|> redirect(to: R.cart())
|
||||
end
|
||||
|
||||
@doc """
|
||||
@@ -82,11 +82,11 @@ defmodule BerrypodWeb.CartController do
|
||||
def update_country(conn, %{"country" => code}) when is_binary(code) and code != "" do
|
||||
conn
|
||||
|> put_session("country_code", code)
|
||||
|> redirect(to: ~p"/cart")
|
||||
|> redirect(to: R.cart())
|
||||
end
|
||||
|
||||
def update_country(conn, _params) do
|
||||
redirect(conn, to: ~p"/cart")
|
||||
redirect(conn, to: R.cart())
|
||||
end
|
||||
|
||||
defp parse_quantity(str) when is_binary(str) do
|
||||
|
||||
@@ -11,7 +11,7 @@ defmodule BerrypodWeb.CheckoutController do
|
||||
unless Settings.has_secret?("stripe_api_key") do
|
||||
conn
|
||||
|> put_flash(:error, "Checkout isn't available yet")
|
||||
|> redirect(to: ~p"/cart")
|
||||
|> redirect(to: R.cart())
|
||||
else
|
||||
cart_items = Cart.get_from_session(get_session(conn))
|
||||
hydrated = Cart.hydrate(cart_items)
|
||||
@@ -20,12 +20,12 @@ defmodule BerrypodWeb.CheckoutController do
|
||||
hydrated == [] ->
|
||||
conn
|
||||
|> put_flash(:error, "Your basket is empty")
|
||||
|> redirect(to: ~p"/cart")
|
||||
|> redirect(to: R.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")
|
||||
|> redirect(to: R.cart())
|
||||
|
||||
true ->
|
||||
track_checkout_start(conn)
|
||||
@@ -45,7 +45,7 @@ defmodule BerrypodWeb.CheckoutController do
|
||||
|
||||
conn
|
||||
|> put_flash(:error, "Something went wrong. Please try again.")
|
||||
|> redirect(to: ~p"/cart")
|
||||
|> redirect(to: R.cart())
|
||||
end
|
||||
end
|
||||
|
||||
@@ -67,14 +67,12 @@ defmodule BerrypodWeb.CheckoutController do
|
||||
}
|
||||
end)
|
||||
|
||||
base_url = BerrypodWeb.Endpoint.url()
|
||||
|
||||
params =
|
||||
%{
|
||||
mode: "payment",
|
||||
line_items: line_items,
|
||||
success_url: "#{base_url}/checkout/success?session_id={CHECKOUT_SESSION_ID}",
|
||||
cancel_url: "#{base_url}/cart",
|
||||
success_url: R.url(R.checkout_success()) <> "?session_id={CHECKOUT_SESSION_ID}",
|
||||
cancel_url: R.url(R.cart()),
|
||||
metadata: %{"order_id" => order.id},
|
||||
shipping_address_collection: %{
|
||||
allowed_countries: ["GB", "US", "CA", "AU", "DE", "FR", "NL", "IE", "AT", "BE"]
|
||||
@@ -96,7 +94,7 @@ defmodule BerrypodWeb.CheckoutController do
|
||||
|
||||
conn
|
||||
|> put_flash(:error, "Payment setup failed. Please try again.")
|
||||
|> redirect(to: ~p"/cart")
|
||||
|> redirect(to: R.cart())
|
||||
|
||||
{:error, reason} ->
|
||||
Logger.error("Stripe session creation failed: #{inspect(reason)}")
|
||||
@@ -104,7 +102,7 @@ defmodule BerrypodWeb.CheckoutController do
|
||||
|
||||
conn
|
||||
|> put_flash(:error, "Payment setup failed. Please try again.")
|
||||
|> redirect(to: ~p"/cart")
|
||||
|> redirect(to: R.cart())
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -13,17 +13,17 @@ defmodule BerrypodWeb.ContactController do
|
||||
{:ok, _} ->
|
||||
conn
|
||||
|> put_flash(:info, "Message sent! We'll get back to you soon.")
|
||||
|> redirect(to: ~p"/contact")
|
||||
|> redirect(to: R.contact())
|
||||
|
||||
{:error, :invalid_params} ->
|
||||
conn
|
||||
|> put_flash(:error, "Please fill in all required fields.")
|
||||
|> redirect(to: ~p"/contact")
|
||||
|> redirect(to: R.contact())
|
||||
|
||||
{:error, _} ->
|
||||
conn
|
||||
|> put_flash(:error, "Sorry, something went wrong. Please try again.")
|
||||
|> redirect(to: ~p"/contact")
|
||||
|> redirect(to: R.contact())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,7 +19,7 @@ defmodule BerrypodWeb.OrderLookupController do
|
||||
:error,
|
||||
"No orders found for that address. Make sure you use the same email you checked out with."
|
||||
)
|
||||
|> redirect(to: ~p"/contact")
|
||||
|> redirect(to: R.contact())
|
||||
else
|
||||
token = generate_token(email)
|
||||
link = BerrypodWeb.Endpoint.url() <> ~p"/orders/verify/#{token}"
|
||||
@@ -30,14 +30,14 @@ defmodule BerrypodWeb.OrderLookupController do
|
||||
:info,
|
||||
"We've sent a link to your email address. It'll expire after an hour."
|
||||
)
|
||||
|> redirect(to: ~p"/contact")
|
||||
|> redirect(to: R.contact())
|
||||
end
|
||||
end
|
||||
|
||||
def lookup(conn, _params) do
|
||||
conn
|
||||
|> put_flash(:error, "Please enter your email address.")
|
||||
|> redirect(to: ~p"/contact")
|
||||
|> redirect(to: R.contact())
|
||||
end
|
||||
|
||||
def verify(conn, %{"token" => token}) do
|
||||
@@ -45,17 +45,17 @@ defmodule BerrypodWeb.OrderLookupController do
|
||||
{:ok, email} ->
|
||||
conn
|
||||
|> put_session(:order_lookup_email, email)
|
||||
|> redirect(to: ~p"/orders")
|
||||
|> redirect(to: R.orders())
|
||||
|
||||
{:error, :expired} ->
|
||||
conn
|
||||
|> put_flash(:error, "That link has expired. Please request a new one.")
|
||||
|> redirect(to: ~p"/contact")
|
||||
|> redirect(to: R.contact())
|
||||
|
||||
{:error, _} ->
|
||||
conn
|
||||
|> put_flash(:error, "That link is invalid.")
|
||||
|> redirect(to: ~p"/contact")
|
||||
|> redirect(to: R.contact())
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ defmodule BerrypodWeb.SeoController do
|
||||
use BerrypodWeb, :controller
|
||||
|
||||
alias Berrypod.{Pages, Products}
|
||||
alias BerrypodWeb.R
|
||||
|
||||
def robots(conn, _params) do
|
||||
base = BerrypodWeb.Endpoint.url()
|
||||
@@ -29,23 +30,23 @@ defmodule BerrypodWeb.SeoController do
|
||||
categories = Products.list_categories()
|
||||
|
||||
static_pages = [
|
||||
{"/", "daily", "1.0"},
|
||||
{"/collections/all", "daily", "0.9"},
|
||||
{"/about", "monthly", "0.5"},
|
||||
{"/contact", "monthly", "0.5"},
|
||||
{"/delivery", "monthly", "0.5"},
|
||||
{"/privacy", "monthly", "0.3"},
|
||||
{"/terms", "monthly", "0.3"}
|
||||
{R.home(), "daily", "1.0"},
|
||||
{R.collection("all"), "daily", "0.9"},
|
||||
{R.about(), "monthly", "0.5"},
|
||||
{R.contact(), "monthly", "0.5"},
|
||||
{R.delivery(), "monthly", "0.5"},
|
||||
{R.privacy(), "monthly", "0.3"},
|
||||
{R.terms(), "monthly", "0.3"}
|
||||
]
|
||||
|
||||
category_pages =
|
||||
Enum.map(categories, fn cat ->
|
||||
{"/collections/#{cat.slug}", "daily", "0.8"}
|
||||
{R.collection(cat.slug), "daily", "0.8"}
|
||||
end)
|
||||
|
||||
product_pages =
|
||||
Enum.map(products, fn product ->
|
||||
{"/products/#{product.slug}", "weekly", "0.9"}
|
||||
{R.product(product.slug), "weekly", "0.9"}
|
||||
end)
|
||||
|
||||
custom_pages =
|
||||
|
||||
Reference in New Issue
Block a user