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" version = "0.1.0"
author = "Ikigai3" 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" license = "Apache-2.0"
srcDir = "src" srcDir = "src"
installExt = @["nim"] installExt = @["nim"]

Binary file not shown.

BIN
src/a3

Binary file not shown.

View File

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

View File

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

View File

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