099
This commit is contained in:
parent
e8760ab1a7
commit
53dfa0f257
BIN
db5.sqlite3
BIN
db5.sqlite3
Binary file not shown.
@ -533,6 +533,19 @@
|
||||
<td> $ 77.99 </td>
|
||||
<td> May 15, 2015 </td>
|
||||
</tr>
|
||||
|
||||
{% for (id, user) in users.pairs() %}
|
||||
<tr>
|
||||
<td class="py-1">
|
||||
<img src="/a3b/admin/images/faces-clipart/pic-1.png" alt="image" />
|
||||
</td>
|
||||
<td> {{user.lastName}} </td>
|
||||
<td> {{user.email}} </td>
|
||||
<td> {{user.totalQuantity}} </td>
|
||||
<td> {{user.totalPrice}} </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
<tr>
|
||||
<td class="py-1">
|
||||
<img src="/a3b/admin/images/faces-clipart/pic-2.png" alt="image" />
|
||||
|
@ -330,6 +330,7 @@
|
||||
<tbody>
|
||||
{% var total: float = 0.0 %}
|
||||
{% for (id, product) in products.pairs() %}
|
||||
<div><input type="hidden" name="product" value="{{product.id}}"></div>
|
||||
<tr>
|
||||
<td>{{product.name}} <strong class="mx-2">x</strong> {{toFloat(cart[id].quantity)}}</td>
|
||||
<td>₹{{toFloat(cart[id].quantity)*product.price}}</td>
|
||||
|
@ -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])
|
||||
return parseFloat(row[0])
|
||||
|
||||
proc getProductIdByProductName*(db: DbConn, name: string): int=
|
||||
result = parseInt(db.getValue(sql"SELECT id FROM products WHERE name=?", name))
|
||||
|
@ -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]
|
||||
|
@ -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")
|
||||
|
@ -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")
|
||||
compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja")
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user