19th Commit

This commit is contained in:
Aritra Banik
2024-02-08 03:02:04 +05:30
parent c2ef8d11be
commit bb7cf556b3
7 changed files with 96 additions and 21 deletions

View File

@@ -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