From 3f5ade2e7a139bb4405437e8fc5546aafc7b05ef Mon Sep 17 00:00:00 2001 From: unwox Date: Fri, 3 Oct 2025 11:56:37 +0600 Subject: WIP shop --- pages/shop/_product/index.fnl | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) (limited to 'pages/shop/_product/index.fnl') diff --git a/pages/shop/_product/index.fnl b/pages/shop/_product/index.fnl index cb451b7..f8b38f7 100644 --- a/pages/shop/_product/index.fnl +++ b/pages/shop/_product/index.fnl @@ -1,7 +1,7 @@ (import-macros {:compile-html HTML} :macros) (local templates (require :templates)) -(local dicts (require :dicts)) (local lib (require :lib)) +(local shop (require :shop)) (fn text->html [text] (assert (= (type text) "string")) @@ -41,44 +41,32 @@ [name])) 1)) -(fn content [product authenticated?] +(fn content [product basket authenticated?] + (local redirect-url (.. "/shop/" product.name)) (local images []) (for [i 1 5] (table.insert images (. product (.. "image" i)))) [(HTML - [:div {:class "side"} - (templates.header "/shop" authenticated?)]) + [:aside {} + (templates.header "/shop" authenticated?) + (if (< 0 (# basket)) (templates.basket basket redirect-url) "")]) (HTML [:div {:class "content"} - [:div {:class "mb-1"} [:a {:href "/shop"} "⟵ Обратно к списку"]] + [:div {:class "back"} [:a {:href "/shop"} "⟵ Обратно к списку"]] [:div {:class "product-page-layout"} - [:article {} + [:section {} [:h2 {:class "product-page-title"} product.title] (if authenticated? (HTML - [:div {:class "mb-1" :style "margin-top: -0.25rem;"} + [:div {:class "mb-1" :style "margin-top: -0.5rem;"} [:a {:href (.. "/shop/" product.name "/edit")} "% Редактировать"]]) "") - [:div {:class "mb-0-5" :style "font-style: italic;"} - (or (dicts.label dicts.product-type product.type) product.type) ", " - (if (not (lib.empty? product.year)) - (HTML [:span {} [:NO-ESCAPE (.. product.year " год, ")]]) - "") - (if (not (lib.empty? product.volume)) - (HTML [:span {} [:NO-ESCAPE (.. product.volume " мл., ")]]) - "") - (if (not (lib.empty? product.region)) (.. product.region ", ") "") - (if (= product.packaging "piece") - (HTML [:strong {} product.price-per "₽"]) - (HTML [:span {} - [:strong {} [:NO-ESCAPE - (* 50 product.price-per) - "₽ за 50 грамм "]] - [:NO-ESCAPE "(" product.price-per - "₽ за 1 грамм)"]]))] + (templates.add-to-basket-form product "mb-0-5" redirect-url) + (templates.product-overview product "mb-0-5") + [:div {:class "mb-1" :style "font-style: italic;"} product.short-description] (let [link (.. "/static/files/" product.image1)] @@ -105,9 +93,11 @@ (HTML [:img {:class "product-page-img" :src (.. link "-thumbnail.jpg")}]))]))))]]])]) (fn render [request db authenticated?] - (let [product (find-product db request.params._product)] + (let [product (find-product db request.params._product) + order-id (shop.order-id request) + basket (if order-id (shop.basket db order-id) [])] (if (and product (or product.published authenticated?)) - (values 200 {} (templates.base (content product authenticated?))) + (values 200 {} (templates.base (content product basket authenticated?))) (values 404 {} "not found")))) {: render} -- cgit v1.2.3