summaryrefslogtreecommitdiff
path: root/pages/shop/order/_id.fnl
blob: 5c929a3090cd627bfbc03849d620495d880a63a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(import-macros {:compile-html HTML} :macros)
(local templates (require :templates))
(local shop (require :shop))
(local lib (require :lib))
(local dicts (require :dicts))

(local texts
  {:thanks
    (lib.improve-typography
      "Мы получили оповещение о заказе. В ближайшее время свяжемся с вами
       для уточнения деталей.")})

(fn content [order-lines authenticated?]
  (local total (accumulate [sum 0 _ v (ipairs order-lines)]
                 (+ sum (* v.quantity v.price-per))))

  [(HTML [:aside {}
           (templates.header "/shop/order" authenticated?)])
   (HTML
    [:div {:class "content"}
     [:div {:class "back"} [:a {:href "/shop"} "⟵ Обратно к списку"]]
     [:section {}
      [:h2 {} "Спасибо за заказ!"]
      [:p {} texts.thanks]
      (templates.order-lines order-lines)
      [:div {} "—"]
      [:div {} [:strong {} (.. "Итого: " (lib.format-price total) "₽")]]]])])

(fn render [request db authenticated?]
  (let [order-lines (shop.basket db request.params._id)]
    (if (< 0 (# order-lines))
      (values 200 {} (templates.base (content order-lines authenticated?)))
      (values 302 {:Location "/shop"} ""))))

{: render}