summaryrefslogtreecommitdiff
path: root/pages/shop/_product/index.fnl
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2025-10-03 11:56:37 +0600
committerunwox <me@unwox.com>2025-10-13 23:11:01 +0600
commit3f5ade2e7a139bb4405437e8fc5546aafc7b05ef (patch)
tree77c437958d74b591f11ec207d16749cf207a51e3 /pages/shop/_product/index.fnl
parentf5a70e6a446e00969adb866ef2e2d10bf33bc4a8 (diff)
WIP shop
Diffstat (limited to 'pages/shop/_product/index.fnl')
-rw-r--r--pages/shop/_product/index.fnl42
1 files changed, 16 insertions, 26 deletions
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 "&nbsp;год, ")]])
- "")
- (if (not (lib.empty? product.volume))
- (HTML [:span {} [:NO-ESCAPE (.. product.volume "&nbsp;мл., ")]])
- "")
- (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)
- "₽ за&nbsp;50&nbsp;грамм "]]
- [:NO-ESCAPE "(" product.price-per
- "₽ за&nbsp;1&nbsp;грамм)"]]))]
+ (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}