This commit is contained in:
Aritra Banik 2024-02-12 01:32:51 +05:30
parent d724ab53c6
commit 31056a9246

View File

@ -174,7 +174,7 @@ import
ctx.redirect("/cart") ctx.redirect("/cart")
"/checkout" -> [get, post]: "/checkout" -> get:
var var
email: string email: string
@ -185,6 +185,14 @@ import
cart: seq[Cart] cart: seq[Cart]
products: seq[Products] products: seq[Products]
productCount = 0 productCount = 0
countryError = ""
firstNameError = ""
lastNameError = ""
addressError = ""
stateError = ""
zipError = ""
emailError = ""
phoneError = ""
try: try:
email = ctx.cookies["email"] email = ctx.cookies["email"]
@ -230,58 +238,124 @@ import
compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja") compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja")
# "/checkout" -> post: "/checkout" -> post:
# var var
# email: string email: string
# password: string password: string
# db = newDatabase() db = newDatabase()
# productName= "" productName= ""
# quantity = 0 quantity = 0
# cart: seq[Cart] cart: seq[Cart]
# products: seq[Products] products: seq[Products]
# price = 0.0 productCount = 0
# # cookies = ctx.cookies cookies = ctx.cookies
countryError = ""
firstNameError = ""
lastNameError = ""
addressError = ""
stateError = ""
zipError = ""
emailError = ""
phoneError = ""
# try: try:
# email = ctx.cookies["email"] email = ctx.cookies["email"]
# password = ctx.cookies["password"] password = ctx.cookies["password"]
# except: except:
# email = "" email = ""
# password = "" password = ""
# if email == "": try:
# try: productName = ctx.queryParams["prod"]
# productName = ctx.queryParams["prod"] quantity = parseInt(ctx.queryParams["quantity"])
# quantity = parseInt(ctx.queryParams["quantity"]) except:
# except: productName = ""
# productName = "" quantity = 0
# quantity = 0
# if productName == "": if email != "":
# ctx.redirect("/login") productCount = micsCartProductCount(email, password)
# price = db.getPriceByProductName(productName) # if productName == "" and email == "":
# ctx.redirect("/login")
# # var var
# # country = cookies["c_country"] country = cookies["c_country"]
# # firstName = cookies["c_fname"] firstName = cookies["c_fname"]
# # lastName = cookies["c_lname"] lastName = cookies["c_lname"]
# # address = cookies["c_address"] address = cookies["c_address"]
# # state = cookies["c_state_country"] state = cookies["c_state_country"]
# # zip = cookies["c_postal_zip"] zip = cookies["c_postal_zip"]
# # email = cookies["c_email_address"] email1 = cookies["c_email_address"]
# # phone = cookies["c_phone"] phone = cookies["c_phone"]
# else: if country == "": countryError = "Country is Required"
# var
# userId = db.getUserId(email, password)
# cart = db.getUserCart(userId)
# for c, d in cart: if firstName == "": firstNameError = "First Name is Required"
# var product = db.getProductById(d.productId)
# products.add(product)
# compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja") if lastName == "": lastNameError = "Last Name is Required"
if address == "": addressError = "Address is Required"
if state == "": stateError = "State is Required"
if zip == "": zipError = "Zip is Required"
if email1 == "": emailError = "Email is Required"
if phone == "": phoneError = "Phone is Required"
# if countryError == "" and firstNameError == "" and lastNameError == "" and addressError == "" and stateError == "" and zipError == "" and emailError == "" and phoneError == "":
# var
# userId = db.getUserId(email, password)
# cart = db.getUserCart(userId)
# order: Order
# order.userId = userId
# order.country = country
# order.firstName = firstName
# order.lastName = lastName
# order.address = address
# order.state = state
# order.zip = zip
# order.email = email1
# order.phone = phone
# db.createOrder(order)
# for c, d in cart:
# var product = db.getProductById(d.productId)
# products.add(product)
# db.clearCart(userId)
# compileTemplateFile(getScriptDir() / "a3a" / "thankyou.nimja")
# else:
# compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja")
if productName != "":
var
product: Products
ca: Cart
product.id = 1
product.name = productName
product.price = db.getPriceByProductName(productName)
ca.quantity = quantity
products.add(product)
cart.add(ca)
else:
var
userId = db.getUserId(email, password)
cart = db.getUserCart(userId)
for c, d in cart:
var product = db.getProductById(d.productId)
echo product
products.add(product)
compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja")
"/contact" -> get: "/contact" -> get: