23rd Commit
This commit is contained in:
parent
ee0d6ba78d
commit
c4354da63e
16
src/a3.nim
16
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,13 +195,22 @@ import
|
||||
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)
|
||||
|
||||
else:
|
||||
var
|
||||
userId = db.getUserId(email, password)
|
||||
cart = db.getUserCart(userId)
|
||||
products: seq[Products]
|
||||
|
||||
for c, d in cart:
|
||||
var product = db.getProductById(d.productId)
|
||||
|
@ -68,7 +68,7 @@
|
||||
<div class="row mb-5">
|
||||
<div class="col-md-12">
|
||||
<div class="border p-4 rounded" role="alert">
|
||||
Returning customer? <a href="#">Click here</a> to login
|
||||
Returning customer? <a href="/login">Click here</a> to login
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -88,6 +88,7 @@
|
||||
<option value="7">Bahrain</option>
|
||||
<option value="8">Colombia</option>
|
||||
<option value="9">Dominican Republic</option>
|
||||
<option value="10">India</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
@ -172,6 +173,7 @@
|
||||
<option value="7">Bahrain</option>
|
||||
<option value="8">Colombia</option>
|
||||
<option value="9">Dominican Republic</option>
|
||||
<option value="10">India</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@ -268,24 +270,14 @@
|
||||
<th>Total</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{# <tr>
|
||||
<td>Top Up T-Shirt <strong class="mx-2">x</strong> 1</td>
|
||||
<td>$250.00</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Polo Shirt <strong class="mx-2">x</strong> 1</td>
|
||||
<td>$100.00</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-black font-weight-bold"><strong>Cart Subtotal</strong></td>
|
||||
<td class="text-black">$350.00</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-black font-weight-bold"><strong>Order Total</strong></td>
|
||||
<td class="text-black font-weight-bold"><strong>$350.00</strong></td>
|
||||
</tr> #}
|
||||
|
||||
{% var total = 0.0 %}
|
||||
{% if email == "" %}
|
||||
<tr>
|
||||
<td>{{productName}} <strong class="mx-2">x</strong> {{quantity}}</td>
|
||||
<td>₹{{toFloat(quantity)*price}}</td>
|
||||
{% total = total + toFloat(quantity)*price %}
|
||||
</tr>
|
||||
{% else %}
|
||||
{% for (id, product) in products.pairs() %}
|
||||
<tr>
|
||||
<td>{{product.name}} <strong class="mx-2">x</strong> {{toFloat(cart[id].quantity)}}</td>
|
||||
@ -293,6 +285,7 @@
|
||||
</tr>
|
||||
{% total = total + toFloat(cart[id].quantity)*product.price %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
<tr>
|
||||
<td class="text-black font-weight-bold"><strong>Cart Subtotal</strong></td>
|
||||
<td class="text-black">₹{{total}}</td>
|
||||
|
@ -106,7 +106,11 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% if email != "" %}
|
||||
<p><a href="#" class="buy-now btn btn-sm btn-primary" onclick="addToCart()">Add To Cart</a></p>
|
||||
{% else %}
|
||||
<p><a href="#" class="buy-now btn btn-sm btn-primary" onclick="checkOut()">Check Out</a></p>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@ -195,5 +199,12 @@
|
||||
+ '?prod={{productName}}&quantity='
|
||||
+ quantity;
|
||||
}
|
||||
|
||||
function checkOut() {
|
||||
var quantity = document.getElementById("quantity").value;
|
||||
window.location.href = '/checkout'
|
||||
+ '?prod={{productName}}&quantity='
|
||||
+ quantity;
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
@ -79,3 +79,7 @@ proc getProductById*(db: DbConn, id: int): Products =
|
||||
|
||||
proc drop*(db: DbConn) =
|
||||
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])
|
Loading…
Reference in New Issue
Block a user