23rd Commit

This commit is contained in:
Aritra Banik 2024-02-08 22:35:58 +05:30
parent ee0d6ba78d
commit c4354da63e
5 changed files with 46 additions and 24 deletions

BIN
src/a3

Binary file not shown.

View File

@ -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:

View File

@ -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">
@ -171,7 +172,8 @@
<option value="6">Albania</option>
<option value="7">Bahrain</option>
<option value="8">Colombia</option>
<option value="9">Dominican Republic</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>

View File

@ -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 %}

View File

@ -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")
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])