diff --git a/db5.sqlite3 b/db5.sqlite3 index 042280b..bc8d43d 100644 Binary files a/db5.sqlite3 and b/db5.sqlite3 differ diff --git a/src/a3 b/src/a3 index 3c2fb3b..d4359a4 100755 Binary files a/src/a3 and b/src/a3 differ diff --git a/src/a3.nim b/src/a3.nim index a62f650..20b1aa6 100644 --- a/src/a3.nim +++ b/src/a3.nim @@ -4,6 +4,7 @@ import os, nimja/parser, strutils, + strformat, ./a3pkg/[models, mics], ./a3c/[products, users, cart] @@ -80,6 +81,49 @@ import compileTemplateFile(getScriptDir() / "a3a" / "cart.nimja") +"/update-cart" -> get: + + var + email: string + password: string + db = newDatabase() + products: seq[Products] + form = ctx.urlForm + echo form + + try: + email = ctx.cookies["email"] + password = ctx.cookies["password"] + except: + email = "" + password = "" + + if email == "": + ctx.redirect("/login") + + else: + products = micsGetProducts(email, password) + var + userId = db.getUserId(email, password) + cart = db.getUserCart(userId) + cook = ctx.cookies + + # echo cart + # echo cook + # db.updateCart(cook) + + for d, e in cook: + if d.contains("_quantity") == true: + var h = d.split("_") + echo h + for i, j in cart: + # echo i + # echo j + if j.productId == parseInt(h[0]): + db.updateCart(e, j.id) + + ctx.redirect("/cart") + "/add-to-cart" -> get: var diff --git a/src/a3a/cart.nimja b/src/a3a/cart.nimja index e02492e..c470bcd 100644 --- a/src/a3a/cart.nimja +++ b/src/a3a/cart.nimja @@ -103,7 +103,7 @@
-
+
@@ -152,7 +152,7 @@
- +
@@ -181,22 +181,6 @@
{% var total = 0.0 %} {% for (id, product) in products.pairs() %} - {#
-
- Subtotal -
-
- $230.00 -
-
-
-
- Total -
-
- $230.00 -
-
#}
@@ -229,6 +213,28 @@
{% endblock %} \ No newline at end of file diff --git a/src/a3c/cart.nim b/src/a3c/cart.nim index 25d2b7a..141ce52 100644 --- a/src/a3c/cart.nim +++ b/src/a3c/cart.nim @@ -1,4 +1,4 @@ -import db_connector/db_sqlite, strutils +import db_connector/db_sqlite, strutils, strtabs import ../a3pkg/models @@ -49,4 +49,23 @@ proc addToCart*(db: DbConn, cart: Cart) = db.exec(sql"INSERT INTO cart (user_id, product_id, quantity) VALUES (?, ?, ?)", cart.userId, cart.productId, cart.quantity) proc removeFromCart*(db: DbConn, cart: Cart) = - db.exec(sql"DELETE FROM cart WHERE user_id=? AND product_id=?", cart.userId, cart.productId) \ No newline at end of file + db.exec(sql"DELETE FROM cart WHERE user_id=? AND product_id=?", cart.userId, cart.productId) + +proc updateCart*(db: DbConn, quantity: string, id: int) = + # echo id + # echo quantity + # echo userId + # echo db.getAllRows(sql"SELECT * FROM cart WHERE user_id=? AND product_id=?;", userId, parseInt(productId)) + db.exec(sql"UPDATE cart SET quantity=? WHERE id=?", quantity, id) + +# proc updateCart*(db: DbConn, cookies: StringTableRef) = +# echo cookies + +# for d, e in cookies: +# if d.contains("_quantity") == true: +# var h = d.split("_") +# echo h + +# db.exec(sql"UPDATE cart SET quantity=? WHERE id=?", e, h[0]) +# echo parseInt(h[0]) +# echo parseInt(e) \ No newline at end of file diff --git a/src/dd b/src/dd new file mode 100755 index 0000000..c5a7535 Binary files /dev/null and b/src/dd differ diff --git a/src/dd.nim b/src/dd.nim new file mode 100644 index 0000000..a706a15 --- /dev/null +++ b/src/dd.nim @@ -0,0 +1,6 @@ +import strformat + +var i = @['o', 'p', 'r'] +echo i +for q, w in i: + echo fmt"q: {q}, w: {w}" \ No newline at end of file