diff --git a/src/a3 b/src/a3
index a5e400f..b0c84a6 100755
Binary files a/src/a3 and b/src/a3 differ
diff --git a/src/a3.nim b/src/a3.nim
index dd13f19..b57838a 100644
--- a/src/a3.nim
+++ b/src/a3.nim
@@ -181,6 +181,11 @@ import
email: string
password: string
db = newDatabase()
+ productName= ""
+ quantity = 0
+ cart: seq[Cart]
+ products: seq[Products]
+ price = 0.0
try:
email = ctx.cookies["email"]
@@ -190,19 +195,28 @@ import
password = ""
if email == "":
- ctx.redirect("/login")
+ try:
+ productName = ctx.queryParams["prod"]
+ quantity = parseInt(ctx.queryParams["quantity"])
+ except:
+ productName = ""
+ quantity = 0
+
+ if productName == "":
+ ctx.redirect("/login")
+
+ price = db.getPriceByProductName(productName)
else:
var
userId = db.getUserId(email, password)
- cart = db.getUserCart(userId)
- products: seq[Products]
+ cart = db.getUserCart(userId)
for c, d in cart:
var product = db.getProductById(d.productId)
products.add(product)
- compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja")
+ compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja")
"/contact" -> get:
diff --git a/src/a3a/checkout.nimja b/src/a3a/checkout.nimja
index c513078..2bc1103 100644
--- a/src/a3a/checkout.nimja
+++ b/src/a3a/checkout.nimja
@@ -68,7 +68,7 @@
@@ -88,6 +88,7 @@
+
@@ -171,7 +172,8 @@
-
+
+
@@ -268,24 +270,14 @@
Total |
- {#
- Top Up T-Shirt x 1 |
- $250.00 |
-
-
- Polo Shirt x 1 |
- $100.00 |
-
-
- Cart Subtotal |
- $350.00 |
-
-
- Order Total |
- $350.00 |
-
#}
-
{% var total = 0.0 %}
+ {% if email == "" %}
+
+ {{productName}} x {{quantity}} |
+ ₹{{toFloat(quantity)*price}} |
+ {% total = total + toFloat(quantity)*price %}
+
+ {% else %}
{% for (id, product) in products.pairs() %}
{{product.name}} x {{toFloat(cart[id].quantity)}} |
@@ -293,6 +285,7 @@
{% total = total + toFloat(cart[id].quantity)*product.price %}
{% endfor %}
+ {% endif %}
Cart Subtotal |
₹{{total}} |
diff --git a/src/a3a/shop-single.nimja b/src/a3a/shop-single.nimja
index 2f13bba..ee91fb3 100644
--- a/src/a3a/shop-single.nimja
+++ b/src/a3a/shop-single.nimja
@@ -106,7 +106,11 @@
+ {% if email != "" %}
Add To Cart
+ {% else %}
+ Check Out
+ {% endif %}
@@ -195,5 +199,12 @@
+ '?prod={{productName}}&quantity='
+ quantity;
}
+
+ function checkOut() {
+ var quantity = document.getElementById("quantity").value;
+ window.location.href = '/checkout'
+ + '?prod={{productName}}&quantity='
+ + quantity;
+ }
{% endblock %}
diff --git a/src/a3c/products.nim b/src/a3c/products.nim
index 40e0796..fef4f43 100644
--- a/src/a3c/products.nim
+++ b/src/a3c/products.nim
@@ -78,4 +78,8 @@ proc getProductById*(db: DbConn, id: int): Products =
return product
proc drop*(db: DbConn) =
- db.exec(sql"DROP TABLE IF EXISTS products")
\ No newline at end of file
+ db.exec(sql"DROP TABLE IF EXISTS products")
+
+proc getPriceByProductName*(db: DbConn, name: string): float =
+ var row = db.getRow(sql"SELECT price FROM products WHERE name = ?", name)
+ return parseFloat(row[0])
\ No newline at end of file