diff --git a/db5.sqlite3 b/db5.sqlite3
index 7a8891a..82d33c2 100644
Binary files a/db5.sqlite3 and b/db5.sqlite3 differ
diff --git a/src/a3 b/src/a3
index e09ecf5..a7d49a4 100755
Binary files a/src/a3 and b/src/a3 differ
diff --git a/src/a3a/admin/index.html b/src/a3a/admin/index.html
index 7abacbc..8309821 100644
--- a/src/a3a/admin/index.html
+++ b/src/a3a/admin/index.html
@@ -533,6 +533,19 @@
$ 77.99 |
May 15, 2015 |
+
+ {% for (id, user) in users.pairs() %}
+
+
+
+ |
+ {{user.lastName}} |
+ {{user.email}} |
+ {{user.totalQuantity}} |
+ {{user.totalPrice}} |
+
+ {% endfor %}
+
diff --git a/src/a3a/checkout.nimja b/src/a3a/checkout.nimja
index a50c6c5..3f9bde2 100644
--- a/src/a3a/checkout.nimja
+++ b/src/a3a/checkout.nimja
@@ -330,6 +330,7 @@
|
{% var total: float = 0.0 %}
{% for (id, product) in products.pairs() %}
+
{{product.name}} x {{toFloat(cart[id].quantity)}} |
₹{{toFloat(cart[id].quantity)*product.price}} |
diff --git a/src/a3c/products.nim b/src/a3c/products.nim
index 116597c..abc863e 100644
--- a/src/a3c/products.nim
+++ b/src/a3c/products.nim
@@ -87,4 +87,7 @@ proc drop*(db: DbConn) =
proc getPriceByProductName*(db: DbConn, name: string): float =
## getPriceByProductName returns the price of a product by its name
var row = db.getRow(sql"SELECT price FROM products WHERE name = ?", name)
- return parseFloat(row[0])
\ No newline at end of file
+ return parseFloat(row[0])
+
+proc getProductIdByProductName*(db: DbConn, name: string): int=
+ result = parseInt(db.getValue(sql"SELECT id FROM products WHERE name=?", name))
diff --git a/src/a3c/users.nim b/src/a3c/users.nim
index a7878c3..eb577a7 100644
--- a/src/a3c/users.nim
+++ b/src/a3c/users.nim
@@ -59,10 +59,12 @@ proc getUser*(db: DbConn, email, password: string): User =
return user
proc getUserOrdersAmount*(db: DbConn, userId: int): (int, int)=
+ echo userId
var
- row = db.getAllRows(sql"SELECT product_id, quantity FROM orders WHERE user_id=?", userId)
+ row = db.getAllRows(sql"SELECT (product_id, quantity) FROM orders WHERE user_id=?", userId)
totalQuantity = 0
totalPrice = 0
+ echo row
for b, c in row:
var
quantity = c[1]
diff --git a/src/admin.nim b/src/admin.nim
index a060cab..2641d6a 100644
--- a/src/admin.nim
+++ b/src/admin.nim
@@ -1,10 +1,14 @@
import
mike,
nimja,
- ./a3pkg/mics
+ ./a3pkg/mics,
+ ./a3c/users
proc admin*(ctx: Context): string=
var
db = newDatabase()
+ users = db.getUserCartTable()
+
+ echo users
compileTemplateFile(getScriptDir() / "a3a" / "admin" / "index.html")
diff --git a/src/checkout.nim b/src/checkout.nim
index 8cfb212..c2eaff0 100644
--- a/src/checkout.nim
+++ b/src/checkout.nim
@@ -23,6 +23,8 @@ proc checkOut*(ctx: Context): string=
productName = qParams.getOrDefault("prod", "")
quantity = parseInt(qParams.getOrDefault("quantity", "0"))
+ # p = seq[int]
+
if email != "":
productCount = micsCartProductCount(email, password)
@@ -34,8 +36,9 @@ proc checkOut*(ctx: Context): string=
product: Products
ca: Cart
- product.id = 1
+ product.id = db.getProductIdByProductName(productName)
product.name = productName
+ # p1 = db.getProductIdByProductName(productName)
product.price = db.getPriceByProductName(productName)
ca.quantity = quantity
products.add(product)
@@ -51,4 +54,4 @@ proc checkOut*(ctx: Context): string=
var product = db.getProductById(d.productId)
products.add(product)
- compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja")
\ No newline at end of file
+ compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja")
diff --git a/src/validation.nim b/src/validation.nim
index 1ed2f6d..1013b2a 100644
--- a/src/validation.nim
+++ b/src/validation.nim
@@ -44,12 +44,13 @@ proc validationCheckOut*(ctx: Context) =
order: Orders
user: User
- order.userId = userId
- order.country = country
- order.address = address
- order.state = state
- order.postalCode = zip
- order.phoneNumber = phone
+ # order.userId = userId
+ # order.country = country
+ # order.address = address
+ # order.state = state
+ # order.postalCode = zip
+ # order.phoneNumber = phone
+ # order.productId = 0
user.firstName = firstName
user.lastName = lastName
@@ -61,10 +62,22 @@ proc validationCheckOut*(ctx: Context) =
db.createPost(user)
db.clearCart(userId)
- var _ = db.createOrder(order)
+ # var _ = db.createOrder(order)
for c, d in cart:
var product = db.getProductById(d.productId)
+
+ order.userId = userId
+ order.country = country
+ order.address = address
+ order.state = state
+ order.postalCode = zip
+ order.phoneNumber = phone
+ order.productId = d.productId
+ order.quantity = d.quantity
+
+ var _ = db.createOrder(order)
+
products.add(product)
ctx.send(sendThankYou())