From 29854a972b8eee6faf382c6c7e0abb55b533a024 Mon Sep 17 00:00:00 2001 From: Priec Date: Mon, 22 Jun 2026 13:51:40 +0200 Subject: [PATCH] save discount profile is now working perfectly well --- .../views/admin/catalog/_price_preview.html | 8 +++ assets/views/admin/catalog/products.html | 10 ++-- assets/views/macros/ui.html | 15 +++++ src/controllers/admin_products.rs | 60 +++++++++++++++++++ src/shared/pricing.rs | 34 +++++++++++ 5 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 assets/views/admin/catalog/_price_preview.html diff --git a/assets/views/admin/catalog/_price_preview.html b/assets/views/admin/catalog/_price_preview.html new file mode 100644 index 0000000..766af27 --- /dev/null +++ b/assets/views/admin/catalog/_price_preview.html @@ -0,0 +1,8 @@ +{# OOB fragment: effective-price cells recomputed from the unsaved profile + selection on the products page. Each span replaces the matching #eff- + span in the table via htmx out-of-band swap. Rendered by + admin_products::profiles_preview. #} +{% import "macros/ui.html" as ui %} +{% for product in products %} +{{ ui::eff_price(p=product, preview=true) }} +{% endfor %} diff --git a/assets/views/admin/catalog/products.html b/assets/views/admin/catalog/products.html index 63943c1..51cf00e 100644 --- a/assets/views/admin/catalog/products.html +++ b/assets/views/admin/catalog/products.html @@ -40,6 +40,9 @@

{% if profiles | length > 0 %}
- {% if product.effective_reduced %} - {{ product.effective_price }} {{ product.currency }} - (−{{ product.effective_percent_off }}%) - {% else %} - {{ product.effective_price }} {{ product.currency }} - {% endif %} + {{ ui::eff_price(p=product) }} {{ product.stock }} diff --git a/assets/views/macros/ui.html b/assets/views/macros/ui.html index 1aa68d0..605e1bb 100644 --- a/assets/views/macros/ui.html +++ b/assets/views/macros/ui.html @@ -122,6 +122,21 @@ {%- endif %} {%- endmacro badge %} +{# Effective-price cell content for the admin products table. The value is + colored only when it differs from the regular price (effective_reduced); + when equal it renders in the plain text color, unified with the Price column. + `preview=true` uses the info color (an unsaved profile-toggle preview) instead + of the saved primary color. No t() calls, so it is safe inside a macro. #} +{% macro eff_price(p, preview=false) -%} +{%- if preview -%}{% set strong = "text-info" %}{%- else -%}{% set strong = "text-primary dark:text-primary-dark" %}{%- endif -%} +{% if p.effective_reduced %} +{{ p.effective_price }} {{ p.currency }} +(−{{ p.effective_percent_off }}%) +{% else %} +{{ p.effective_price }} {{ p.currency }} +{% endif %} +{%- endmacro eff_price %} + {# ---- Form controls. Verbatim Penguin classes from penguinui/{text-input,text-area,select,checkbox,file-input}/default-*.html. These macros emit only the control (callers keep their own