This commit is contained in:
Priec
2026-06-25 12:12:50 +02:00
parent d3d1c0d157
commit f51875d5f4
14 changed files with 225 additions and 17 deletions

View File

@@ -20,7 +20,7 @@ use crate::{
account, admin_categories, admin_currencies, admin_customers, admin_dashboard,
admin_discount_profiles, admin_form, admin_orders, admin_products, admin_shipping,
auth, auth_pages, cart, checkout, currency, home, i18n, media, oauth2,
shop,
pages, shop,
},
initializers,
models::_entities::users,
@@ -97,6 +97,7 @@ impl Hooks for App {
.add_route(cart::routes())
.add_route(checkout::routes())
.add_route(currency::routes())
.add_route(pages::routes())
// cross-cutting
.add_route(auth::routes())
.add_route(auth_pages::routes())

View File

@@ -17,4 +17,5 @@ pub mod currency;
pub mod home;
pub mod i18n;
pub mod media;
pub mod pages;
pub mod shop;

96
src/controllers/pages.rs Normal file
View File

@@ -0,0 +1,96 @@
//! Static informational pages (contact, sitemap, terms, about, stores,
//! shipping). These back the top-bar / footer / sidebar links so none of them
//! is a dead `#`. Content is static; the same chrome context as the home page
//! is supplied so `base.html` (header, cart badge, currencies) renders.
use axum_extra::extract::cookie::CookieJar;
use loco_rs::prelude::*;
use serde_json::json;
use crate::{controllers::i18n::current_lang, shared::currency, shared::guard};
/// Render one static page through `pages/info.html`, which switches its title +
/// body on the `page` slug. Mirrors `home::index`'s chrome wiring.
async fn render(v: &TeraView, jar: &CookieJar, ctx: &AppContext, page: &str) -> Result<Response> {
let user = guard::current_user(ctx, jar).await;
let cur = currency::resolve(ctx, jar).await;
let c = guard::chrome_from(ctx, user.as_ref());
format::view(
v,
"pages/info.html",
json!({
"page": page,
"logged_in_admin": c.logged_in_admin,
"logged_in_customer": c.logged_in_customer,
"customer_name": c.customer_name,
"customer_account_type": c.customer_account_type,
"currency_symbol": cur.symbol,
"lang": current_lang(jar),
}),
)
}
#[debug_handler]
async fn contact(
jar: CookieJar,
ViewEngine(v): ViewEngine<TeraView>,
State(ctx): State<AppContext>,
) -> Result<Response> {
render(&v, &jar, &ctx, "contact").await
}
#[debug_handler]
async fn sitemap(
jar: CookieJar,
ViewEngine(v): ViewEngine<TeraView>,
State(ctx): State<AppContext>,
) -> Result<Response> {
render(&v, &jar, &ctx, "sitemap").await
}
#[debug_handler]
async fn terms(
jar: CookieJar,
ViewEngine(v): ViewEngine<TeraView>,
State(ctx): State<AppContext>,
) -> Result<Response> {
render(&v, &jar, &ctx, "terms").await
}
#[debug_handler]
async fn about(
jar: CookieJar,
ViewEngine(v): ViewEngine<TeraView>,
State(ctx): State<AppContext>,
) -> Result<Response> {
render(&v, &jar, &ctx, "about").await
}
#[debug_handler]
async fn stores(
jar: CookieJar,
ViewEngine(v): ViewEngine<TeraView>,
State(ctx): State<AppContext>,
) -> Result<Response> {
render(&v, &jar, &ctx, "stores").await
}
#[debug_handler]
async fn shipping(
jar: CookieJar,
ViewEngine(v): ViewEngine<TeraView>,
State(ctx): State<AppContext>,
) -> Result<Response> {
render(&v, &jar, &ctx, "shipping").await
}
pub fn routes() -> Routes {
Routes::new()
.add("/kontakt", get(contact))
.add("/mapa-stranky", get(sitemap))
.add("/obchodne-podmienky", get(terms))
.add("/o-nas", get(about))
.add("/predajne", get(stores))
.add("/doprava-a-platba", get(shipping))
}

View File

@@ -22,6 +22,14 @@ pub fn product_card(
category_name: Option<String>,
cur: &Currency,
) -> Value {
// Whole-percent discount for the card's sale badge (e.g. "15 %"). Only
// meaningful when the resolved price is actually reduced below the regular.
let percent_off = if priced.is_reduced() && priced.regular_cents > priced.price_cents {
(((priced.regular_cents - priced.price_cents) as f64 / priced.regular_cents as f64) * 100.0)
.round() as i64
} else {
0
};
json!({
"id": product.id,
"variant_id": representative.id,
@@ -31,6 +39,7 @@ pub fn product_card(
"short_description": product.short_description,
"price": cur.format(priced.price_cents),
"on_sale": priced.is_reduced(),
"percent_off": percent_off,
"is_business": priced.is_business,
"regular_price": cur.format(priced.regular_cents),
"sku": representative.sku,