Jelajahi Sumber

customize ingredients, except add from other menu items.

Harlan Iverson 5 tahun lalu
induk
melakukan
e64569e7fc
2 mengubah file dengan 16 tambahan dan 10 penghapusan
  1. 15 8
      src/pos_demo/core.cljs
  2. 1 2
      src/pos_demo/order.cljs

+ 15 - 8
src/pos_demo/core.cljs

@@ -145,10 +145,8 @@
 (defn add-menu-item-to-order
   [menu-item-id]
   ;(swap! app-state update-in [:active-order :items] conj (select-keys menu-item [:title :price]))
-  (let [ingredient-mods (if (= 102 menu-item-id)
-                          {"Bread" {:operation :skip}
-                           "Lettuce" {:operation :add}}
-                          {})
+  (let [;menu-item (menu/find-menu-item menu-item-id)
+        ingredient-mods (or (get (@app-state :sides) menu-item-id) {})
         request (order/request-menu-item (:active-order @app-state) menu-item-id ingredient-mods)]
     (order/add-item request))
   (swap! app-state assoc :payment-amount (str (order/order-total (:active-order @app-state)))))
@@ -157,12 +155,14 @@
   [menu item]
 
   ; show modal to customize based on ingredients.  
+  (swap! app-state dissoc :sides)
   (swap! app-state assoc :customize-menu-item item))
 
 (defn add-item-clicked
   [menu item]
-  (swap! app-state dissoc :customize-menu-item)
   (add-menu-item-to-order (:id item))
+  (swap! app-state dissoc :customize-menu-item)
+  (swap! app-state dissoc :sides)
   (.scrollTo js/window 0 0))
 
 (defn login-clicked
@@ -203,6 +203,10 @@
     [:strong "Total Price"]
     [:span (str (order/order-total order))]]])
 
+(defn custom-ingredient-modifier-clicked
+  [menu-item ingredient operation]
+  (swap! app-state assoc-in [:sides (:id menu-item) (:ingredient ingredient)] {:operation operation}))
+
 (defn customize-menu-item [menu-item]
   [:div#product-customization-dialog
    [:h4 (:title menu-item)]
@@ -216,9 +220,12 @@
     (for [k (menu/find-menu-item-ingredients (:id menu-item))]
       [:li [:h5 (:ingredient k)]
        [:p (:description k)]
-       [:div (button "On Side" #(js/alert "Not implemented yet.") {:height "30px"})
-        (button "Extra" #(js/alert "Not implemented yet.") {:height "30px"})
-        (button "Skip" #(js/alert "Not implemented yet.") {:height "30px"})]])
+       [:div (button "Double" #(custom-ingredient-modifier-clicked menu-item k :double) {:height "30px"})
+       (button "On Side" #(custom-ingredient-modifier-clicked menu-item k :on-side) {:height "30px"})
+        (button "Extra Side" #(custom-ingredient-modifier-clicked menu-item k :extra-side) {:height "30px"})
+        (button "Double On Side" #(custom-ingredient-modifier-clicked menu-item k :double-side) {:height "30px"})
+        (button "Skip" #(custom-ingredient-modifier-clicked menu-item k :skip) {:height "30px"})
+        (button "Normal" #(custom-ingredient-modifier-clicked menu-item k :normal) {:height "30px"})]])
     [:li
      [:h5 "Something else?"]
      [:p "Add any ingredient from any item on the menu."]

+ 1 - 2
src/pos_demo/order.cljs

@@ -75,5 +75,4 @@
         total-price (reduce decimal/+
                             "0.00"
                             item-prices)]
-    total-price))
-
+    total-price))