This commit is contained in:
Aritra Banik 2024-02-11 02:53:43 +05:30
parent ab9f20f713
commit d724ab53c6
6 changed files with 90 additions and 67 deletions

View File

@ -2,7 +2,7 @@
version = "0.1.0"
author = "Ikigai3"
description = "A new awesome nimble package"
description = "A new awesome E-Commerce website with a fully functional admin panel."
license = "Apache-2.0"
srcDir = "src"
installExt = @["nim"]

Binary file not shown.

BIN
src/a3

Binary file not shown.

View File

@ -174,7 +174,7 @@ import
ctx.redirect("/cart")
"/checkout" -> get:
"/checkout" -> [get, post]:
var
email: string
@ -184,7 +184,7 @@ import
quantity = 0
cart: seq[Cart]
products: seq[Products]
price = 0.0
productCount = 0
try:
email = ctx.cookies["email"]
@ -200,63 +200,23 @@ import
productName = ""
quantity = 0
if productName == "":
if email != "":
productCount = micsCartProductCount(email, password)
if productName == "" and email == "":
ctx.redirect("/login")
price = db.getPriceByProductName(productName)
if email != "":
elif productName != "":
var
userId = db.getUserId(email, password)
cart = db.getUserCart(userId)
product: Products
ca: Cart
for c, d in cart:
var product = db.getProductById(d.productId)
products.add(product)
compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja")
"/checkout" -> post:
var
email: string
password: string
db = newDatabase()
productName= ""
quantity = 0
cart: seq[Cart]
products: seq[Products]
price = 0.0
# cookies = ctx.cookies
try:
email = ctx.cookies["email"]
password = ctx.cookies["password"]
except:
email = ""
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)
# var
# country = cookies["c_country"]
# firstName = cookies["c_fname"]
# lastName = cookies["c_lname"]
# address = cookies["c_address"]
# state = cookies["c_state_country"]
# zip = cookies["c_postal_zip"]
# email = cookies["c_email_address"]
# phone = cookies["c_phone"]
product.id = 1
product.name = productName
product.price = db.getPriceByProductName(productName)
ca.quantity = quantity
products.add(product)
cart.add(ca)
else:
var
@ -265,10 +225,64 @@ import
for c, d in cart:
var product = db.getProductById(d.productId)
echo product
products.add(product)
compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja")
# "/checkout" -> post:
# var
# email: string
# password: string
# db = newDatabase()
# productName= ""
# quantity = 0
# cart: seq[Cart]
# products: seq[Products]
# price = 0.0
# # cookies = ctx.cookies
# try:
# email = ctx.cookies["email"]
# password = ctx.cookies["password"]
# except:
# email = ""
# 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)
# # var
# # country = cookies["c_country"]
# # firstName = cookies["c_fname"]
# # lastName = cookies["c_lname"]
# # address = cookies["c_address"]
# # state = cookies["c_state_country"]
# # zip = cookies["c_postal_zip"]
# # email = cookies["c_email_address"]
# # phone = cookies["c_phone"]
# else:
# var
# userId = db.getUserId(email, password)
# cart = db.getUserCart(userId)
# for c, d in cart:
# var product = db.getProductById(d.productId)
# products.add(product)
# compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja")
"/contact" -> get:
var
@ -388,9 +402,17 @@ import
emailError = ""
passwordError = ""
productName: string
quantity: int
try:
productName = ctx.queryParams["prod"]
quantity = parseInt(ctx.queryParams["quantity"])
except:
productName = ""
quantity = 0
if user == true:
ctx &= initCookie("email", email)

View File

@ -32,8 +32,8 @@
<span class="icon icon-shopping_cart"></span>
{# <span class="count">2</span> #}
{% if email != "" %}
{% if products.len > 0 %}
<span class="count">{{products.len}}</span>
{% if productCount > 0 %}
<span class="count">{{productCount}}</span>
{% endif %}
{% endif %}
</a>
@ -275,14 +275,7 @@
<th>Total</th>
</thead>
<tbody>
{% var total = 0.0 %}
{% if productName != "" %}
<tr>
<td>{{productName}} <strong class="mx-2">x</strong> {{quantity}}</td>
<td>₹{{toFloat(quantity)*price}}</td>
{% total = total + toFloat(quantity)*price %}
</tr>
{% else %}
{% var total: float = 0.0 %}
{% for (id, product) in products.pairs() %}
<tr>
<td>{{product.name}} <strong class="mx-2">x</strong> {{toFloat(cart[id].quantity)}}</td>
@ -290,7 +283,6 @@
</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

@ -19,3 +19,12 @@ proc micsGetProducts*(email, password: string): seq[Products]=
products.add(product)
return products
proc micsCartProductCount*(email, password: string): int =
var
db = newDatabase()
userId = db.getUserId(email, password)
cart = db.getUserCart(userId)
result = cart.len