029
This commit is contained in:
parent
ab9f20f713
commit
d724ab53c6
@ -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"]
|
||||||
|
BIN
db5.sqlite3
BIN
db5.sqlite3
Binary file not shown.
130
src/a3.nim
130
src/a3.nim
@ -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 == "":
|
|
||||||
ctx.redirect("/login")
|
|
||||||
|
|
||||||
price = db.getPriceByProductName(productName)
|
|
||||||
|
|
||||||
if email != "":
|
if email != "":
|
||||||
var
|
productCount = micsCartProductCount(email, password)
|
||||||
userId = db.getUserId(email, password)
|
|
||||||
cart = db.getUserCart(userId)
|
|
||||||
|
|
||||||
for c, d in cart:
|
if productName == "" and email == "":
|
||||||
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")
|
ctx.redirect("/login")
|
||||||
|
|
||||||
price = db.getPriceByProductName(productName)
|
elif productName != "":
|
||||||
|
var
|
||||||
|
product: Products
|
||||||
|
ca: Cart
|
||||||
|
|
||||||
# var
|
product.id = 1
|
||||||
# country = cookies["c_country"]
|
product.name = productName
|
||||||
# firstName = cookies["c_fname"]
|
product.price = db.getPriceByProductName(productName)
|
||||||
# lastName = cookies["c_lname"]
|
ca.quantity = quantity
|
||||||
# address = cookies["c_address"]
|
products.add(product)
|
||||||
# state = cookies["c_state_country"]
|
cart.add(ca)
|
||||||
# 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)
|
||||||
|
@ -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>
|
||||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user