From bf8f8e54c948ea466a86ac1b6b470d42675ba93e Mon Sep 17 00:00:00 2001
From: Priec
- {% 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 |