diff --git a/assets/views/admin/base.html b/assets/views/admin/base.html index 7db4ee5..a701385 100644 --- a/assets/views/admin/base.html +++ b/assets/views/admin/base.html @@ -78,10 +78,6 @@ class="flex items-center gap-2 rounded-radius px-2 py-1.5 text-sm font-medium text-on-surface underline-offset-2 transition hover:bg-primary/5 hover:text-on-surface-strong focus:outline-hidden focus-visible:underline aria-[current=page]:bg-primary/10 aria-[current=page]:text-on-surface-strong dark:text-on-surface-dark dark:hover:bg-primary-dark/5 dark:hover:text-on-surface-dark-strong dark:aria-[current=page]:bg-primary-dark/10 dark:aria-[current=page]:text-on-surface-dark-strong"> {{ t(key="admin-products", lang=lang | default(value='sk')) }} - - {{ t(key="admin-discounts", lang=lang | default(value='sk')) }} - {{ t(key="admin-discount-profiles", lang=lang | default(value='sk')) }} diff --git a/assets/views/admin/catalog/discount_form.html b/assets/views/admin/catalog/discount_form.html index 7b3d1f5..d520d27 100644 --- a/assets/views/admin/catalog/discount_form.html +++ b/assets/views/admin/catalog/discount_form.html @@ -12,10 +12,10 @@ {% if audience == "business" %}{{ t(key="audience-business", lang=lang | default(value='sk')) }}{% else %}{{ t(key="audience-personal", lang=lang | default(value='sk')) }}{% endif %}
- {{ ui::button(variant="outline-secondary", label=t(key="cancel", lang=lang | default(value='sk')), href="/admin/catalog/discounts?audience=" ~ audience, size="px-3 py-2 text-sm") }} + {{ ui::button(variant="outline-secondary", label=t(key="cancel", lang=lang | default(value='sk')), href="/admin/catalog/products?audience=" ~ audience, size="px-3 py-2 text-sm") }} - diff --git a/assets/views/admin/catalog/discounts.html b/assets/views/admin/catalog/discounts.html deleted file mode 100644 index 7a8f146..0000000 --- a/assets/views/admin/catalog/discounts.html +++ /dev/null @@ -1,125 +0,0 @@ -{% extends "admin/base.html" %} -{% import "macros/ui.html" as ui %} - -{% block title %}{{ t(key="admin-discounts", lang=lang | default(value='sk')) }}{% endblock title %} -{% block crumb %}{{ t(key="admin-discounts", lang=lang | default(value='sk')) }}{% endblock crumb %} - -{% block content %} -{% set business = audience == "business" %} -- {% if business %}{{ t(key="business-discount-desc", lang=lang | default(value='sk')) }}{% else %}{{ t(key="admin-discounts-desc", lang=lang | default(value='sk')) }}{% endif %} -
-- {% if business %}{{ t(key="apply-profiles-business-hint", lang=lang | default(value='sk')) }}{% else %}{{ t(key="apply-profiles-personal-hint", lang=lang | default(value='sk')) }}{% endif %} -
- {% if profiles | length > 0 %} - - {% else %} -- {{ t(key="admin-no-profiles", lang=lang | default(value='sk')) }} - {{ t(key="new-profile", lang=lang | default(value='sk')) }} -
- {% endif %} -|
- {{ product.name }}
- |
- {{ product.regular_price }} {{ product.currency }} | -- {% if on_sale %} - {{ sale_price }} {{ product.currency }} - (−{{ pct }}%) - {% else %} - — - {% endif %} - | -- {% if product.effective_reduced %} - {{ product.effective_price }} {{ product.currency }} - (−{{ product.effective_percent_off }}%) - {% else %} - {{ product.effective_price }} {{ product.currency }} - {% endif %} - | -- {% if on_sale %} - {{ ui::badge(label=t(key="on-sale", lang=lang | default(value='sk')), variant="danger") }} - {% else %} - {{ ui::badge(label=t(key="no-discount", lang=lang | default(value='sk')), variant="neutral") }} - {% endif %} - | -
-
- {{ ui::button(variant="outline-secondary", label=t(key="set-discount", lang=lang | default(value='sk')), href="/admin/catalog/discounts/" ~ product.id ~ "/edit?audience=" ~ audience, size="px-3 py-1.5 text-xs") }}
- {% if on_sale %}
-
- {% endif %}
-
- |
-
{{ t(key="admin-no-products", lang=lang | default(value='sk')) }}
-+ {% if business %}{{ t(key="apply-profiles-business-hint", lang=lang | default(value='sk')) }}{% else %}{{ t(key="apply-profiles-personal-hint", lang=lang | default(value='sk')) }}{% endif %} +
+ {% if profiles | length > 0 %} + + {% else %} ++ {{ t(key="admin-no-profiles", lang=lang | default(value='sk')) }} + {{ t(key="new-profile", lang=lang | default(value='sk')) }} +
+ {% endif %} +| {{ product.regular_price }} {{ product.currency }} | {% if product.on_sale %} - {{ product.price }} {{ product.currency }} - {{ product.regular_price }} + {{ product.sale_price }} {{ product.currency }} + (−{{ product.percent_off }}%) {% else %} - {{ product.price }} {{ product.currency }} + — + {% endif %} + | ++ {% if product.effective_reduced %} + {{ product.effective_price }} {{ product.currency }} + (−{{ product.effective_percent_off }}%) + {% else %} + {{ product.effective_price }} {{ product.currency }} {% endif %} | {{ product.stock }} | @@ -60,11 +112,18 @@
{{ ui::button(variant="outline-secondary", label=t(key="edit", lang=lang | default(value='sk')), href="/admin/catalog/products/" ~ product.id ~ "/edit", size="px-3 py-1.5 text-xs") }}
- {{ ui::button(variant="outline-secondary", label=t(key="discount", lang=lang | default(value='sk')), href="/admin/catalog/discounts/" ~ product.id ~ "/edit", size="px-3 py-1.5 text-xs") }}
+ {{ ui::button(variant="outline-secondary", label=t(key="set-discount", lang=lang | default(value='sk')), href="/admin/catalog/products/" ~ product.id ~ "/discount/edit?audience=" ~ audience, size="px-3 py-1.5 text-xs") }}
+ {% if product.on_sale %}
+
+ {% endif %}
{{ ui::button(variant="outline-secondary", label=t(key="view", lang=lang | default(value='sk')), href="/shop/" ~ product.slug, size="px-3 py-1.5 text-xs") }}
diff --git a/src/app.rs b/src/app.rs
index ca07554..dfa4791 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -18,7 +18,7 @@ use std::{path::Path, sync::Arc};
use crate::{
controllers::{
account, admin_categories, admin_customers, admin_dashboard, admin_discount_profiles,
- admin_discounts, admin_form, admin_orders, admin_products, admin_shipping, auth, auth_pages,
+ admin_form, admin_orders, admin_products, admin_shipping, auth, auth_pages,
cart, checkout, home, i18n, media, oauth2,
shop,
},
@@ -105,7 +105,6 @@ impl Hooks for App {
// admin
.add_route(admin_dashboard::routes())
.add_route(admin_products::routes())
- .add_route(admin_discounts::routes())
.add_route(admin_discount_profiles::routes())
.add_route(admin_categories::routes())
.add_route(admin_orders::routes())
diff --git a/src/controllers/admin_discounts.rs b/src/controllers/admin_discounts.rs
deleted file mode 100644
index 2f0ffbd..0000000
--- a/src/controllers/admin_discounts.rs
+++ /dev/null
@@ -1,370 +0,0 @@
-//! Admin management of per-product discounts, in a place of their own rather
-//! than on the product editor.
-//!
-//! Two audiences, switched by an `?audience=` tab:
-//! - **personal** (default): the public sale price (`products.sale_price_cents`)
-//! everyone sees.
-//! - **business**: a baseline discount for all company accounts
-//! (`products.business_sale_price_cents`). Per-company profiles/negotiated
-//! prices still layer on top (lowest price wins). Both are computed off the
-//! regular price.
-
-use std::collections::{HashMap, HashSet};
-
-use axum_extra::extract::cookie::CookieJar;
-use loco_rs::prelude::*;
-use sea_orm::{
- ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, QueryOrder, Set, TransactionTrait,
-};
-use serde::Deserialize;
-use serde_json::json;
-
-use crate::{
- controllers::i18n::current_lang,
- models::{audience_discount_profiles, discount_profiles, products},
- shared::{
- guard,
- money::{format_bp, format_price, parse_percent, parse_price_to_cents},
- pricing,
- },
-};
-
-const BUSINESS: &str = "business";
-
-#[derive(Debug, Deserialize)]
-struct DiscountForm {
- /// "fixed" (enter the new price) or "percent" (enter % off). Defaults to
- /// fixed for older/JSON callers.
- mode: Option |