diff --git a/a3.nimble b/a3.nimble index 8cf6050..0dbc3be 100644 --- a/a3.nimble +++ b/a3.nimble @@ -2,7 +2,7 @@ version = "0.1.0" author = "Ikigai3" -description = "A new awesome nimble package" +description = "A new awesome E-Commerce website with a fully functional admin panel." license = "Apache-2.0" srcDir = "src" installExt = @["nim"] diff --git a/db5.sqlite3 b/db5.sqlite3 index b3a9bc0..37ee38e 100644 Binary files a/db5.sqlite3 and b/db5.sqlite3 differ diff --git a/src/a3 b/src/a3 index 99b04d6..d7b5366 100755 Binary files a/src/a3 and b/src/a3 differ diff --git a/src/a3.nim b/src/a3.nim index 2b5ac45..c797cc6 100644 --- a/src/a3.nim +++ b/src/a3.nim @@ -174,7 +174,7 @@ import ctx.redirect("/cart") -"/checkout" -> get: +"/checkout" -> [get, post]: var email: string @@ -184,7 +184,7 @@ import quantity = 0 cart: seq[Cart] products: seq[Products] - price = 0.0 + productCount = 0 try: email = ctx.cookies["email"] @@ -200,63 +200,23 @@ import productName = "" quantity = 0 - if productName == "": + if email != "": + productCount = micsCartProductCount(email, password) + + if productName == "" and email == "": ctx.redirect("/login") - price = db.getPriceByProductName(productName) - - if email != "": + elif productName != "": var - userId = db.getUserId(email, password) - cart = db.getUserCart(userId) - - for c, d in cart: - var product = db.getProductById(d.productId) - products.add(product) + product: Products + ca: Cart - compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja") - -"/checkout" -> post: - var - email: string - password: string - db = newDatabase() - productName= "" - quantity = 0 - cart: seq[Cart] - products: seq[Products] - price = 0.0 - # cookies = ctx.cookies - - try: - email = ctx.cookies["email"] - password = ctx.cookies["password"] - except: - email = "" - password = "" - - if email == "": - try: - productName = ctx.queryParams["prod"] - quantity = parseInt(ctx.queryParams["quantity"]) - except: - productName = "" - quantity = 0 - - if productName == "": - ctx.redirect("/login") - - price = db.getPriceByProductName(productName) - - # var - # country = cookies["c_country"] - # firstName = cookies["c_fname"] - # lastName = cookies["c_lname"] - # address = cookies["c_address"] - # state = cookies["c_state_country"] - # zip = cookies["c_postal_zip"] - # email = cookies["c_email_address"] - # phone = cookies["c_phone"] + product.id = 1 + product.name = productName + product.price = db.getPriceByProductName(productName) + ca.quantity = quantity + products.add(product) + cart.add(ca) else: var @@ -265,10 +225,64 @@ import for c, d in cart: var product = db.getProductById(d.productId) + echo product products.add(product) compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja") +# "/checkout" -> post: +# var +# email: string +# password: string +# db = newDatabase() +# productName= "" +# quantity = 0 +# cart: seq[Cart] +# products: seq[Products] +# price = 0.0 +# # cookies = ctx.cookies + +# try: +# email = ctx.cookies["email"] +# password = ctx.cookies["password"] +# except: +# email = "" +# password = "" + +# if email == "": +# try: +# productName = ctx.queryParams["prod"] +# quantity = parseInt(ctx.queryParams["quantity"]) +# except: +# productName = "" +# quantity = 0 + +# if productName == "": +# ctx.redirect("/login") + +# price = db.getPriceByProductName(productName) + +# # var +# # country = cookies["c_country"] +# # firstName = cookies["c_fname"] +# # lastName = cookies["c_lname"] +# # address = cookies["c_address"] +# # state = cookies["c_state_country"] +# # zip = cookies["c_postal_zip"] +# # email = cookies["c_email_address"] +# # phone = cookies["c_phone"] + +# else: +# var +# userId = db.getUserId(email, password) +# cart = db.getUserCart(userId) + +# for c, d in cart: +# var product = db.getProductById(d.productId) +# products.add(product) + +# compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja") + "/contact" -> get: var @@ -388,9 +402,17 @@ import emailError = "" passwordError = "" + productName: string + quantity: int + + try: productName = ctx.queryParams["prod"] quantity = parseInt(ctx.queryParams["quantity"]) + except: + productName = "" + quantity = 0 + if user == true: ctx &= initCookie("email", email) diff --git a/src/a3a/checkout.nimja b/src/a3a/checkout.nimja index 5b1ef33..709d606 100644 --- a/src/a3a/checkout.nimja +++ b/src/a3a/checkout.nimja @@ -32,8 +32,8 @@ {# 2 #} {% if email != "" %} - {% if products.len > 0 %} - {{products.len}} + {% if productCount > 0 %} + {{productCount}} {% endif %} {% endif %} @@ -275,14 +275,7 @@ Total - {% var total = 0.0 %} - {% if productName != "" %} - - {{productName}} x {{quantity}} - ₹{{toFloat(quantity)*price}} - {% total = total + toFloat(quantity)*price %} - - {% else %} + {% var total: float = 0.0 %} {% for (id, product) in products.pairs() %} {{product.name}} x {{toFloat(cart[id].quantity)}} @@ -290,7 +283,6 @@ {% total = total + toFloat(cart[id].quantity)*product.price %} {% endfor %} - {% endif %} Cart Subtotal ₹{{total}} diff --git a/src/a3pkg/mics.nim b/src/a3pkg/mics.nim index 1c34e74..40fbfcf 100644 --- a/src/a3pkg/mics.nim +++ b/src/a3pkg/mics.nim @@ -19,3 +19,12 @@ proc micsGetProducts*(email, password: string): seq[Products]= products.add(product) return products + +proc micsCartProductCount*(email, password: string): int = + var + db = newDatabase() + + userId = db.getUserId(email, password) + cart = db.getUserCart(userId) + + result = cart.len \ No newline at end of file