031
This commit is contained in:
parent
31056a9246
commit
b5b52e8be0
BIN
db5.sqlite3
BIN
db5.sqlite3
Binary file not shown.
120
src/a3.nim
120
src/a3.nim
@ -6,7 +6,7 @@ import
|
||||
strutils,
|
||||
strformat,
|
||||
./a3pkg/[models, mics],
|
||||
./a3c/[products, users, cart]
|
||||
./a3c/[products, users, cart, orders]
|
||||
|
||||
"/" -> [get, post]:
|
||||
|
||||
@ -193,6 +193,7 @@ import
|
||||
zipError = ""
|
||||
emailError = ""
|
||||
phoneError = ""
|
||||
ch = ""
|
||||
|
||||
try:
|
||||
email = ctx.cookies["email"]
|
||||
@ -225,6 +226,7 @@ import
|
||||
ca.quantity = quantity
|
||||
products.add(product)
|
||||
cart.add(ca)
|
||||
ch = "d"
|
||||
|
||||
else:
|
||||
var
|
||||
@ -257,6 +259,8 @@ import
|
||||
zipError = ""
|
||||
emailError = ""
|
||||
phoneError = ""
|
||||
passwordError = ""
|
||||
ch = ""
|
||||
|
||||
try:
|
||||
email = ctx.cookies["email"]
|
||||
@ -272,9 +276,6 @@ import
|
||||
productName = ""
|
||||
quantity = 0
|
||||
|
||||
if email != "":
|
||||
productCount = micsCartProductCount(email, password)
|
||||
|
||||
# if productName == "" and email == "":
|
||||
# ctx.redirect("/login")
|
||||
|
||||
@ -287,75 +288,82 @@ import
|
||||
zip = cookies["c_postal_zip"]
|
||||
email1 = cookies["c_email_address"]
|
||||
phone = cookies["c_phone"]
|
||||
password1: string
|
||||
|
||||
echo cookies
|
||||
|
||||
try:
|
||||
password1 = cookies["password"]
|
||||
except:
|
||||
password1 = ""
|
||||
|
||||
if country == "": countryError = "Country is Required"
|
||||
|
||||
if firstName == "": firstNameError = "First Name is Required"
|
||||
|
||||
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
|
||||
if email != "":
|
||||
productCount = micsCartProductCount(email, password)
|
||||
|
||||
# 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:
|
||||
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)
|
||||
|
||||
cart = db.getUserCart(userId)
|
||||
order: Orders
|
||||
user: User
|
||||
|
||||
order.userId = userId
|
||||
order.country = country
|
||||
order.address = address
|
||||
order.state = state
|
||||
order.postalCode = zip
|
||||
order.phoneNumber = phone
|
||||
|
||||
user.firstName = firstName
|
||||
user.lastName = lastName
|
||||
user.email = email1
|
||||
|
||||
if email == "":
|
||||
user.password = password1
|
||||
user.accessLevel = 1
|
||||
db.createPost(user)
|
||||
db.clearCart(userId)
|
||||
|
||||
var _ = db.createOrder(order)
|
||||
|
||||
for c, d in cart:
|
||||
var product = db.getProductById(d.productId)
|
||||
echo product
|
||||
products.add(product)
|
||||
|
||||
compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja")
|
||||
compileTemplateFile(getScriptDir() / "a3a" / "thankyou.nimja")
|
||||
|
||||
else:
|
||||
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)
|
||||
products.add(product)
|
||||
|
||||
compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja")
|
||||
|
||||
"/contact" -> get:
|
||||
|
||||
|
@ -77,12 +77,17 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
{% if ch == "" %}
|
||||
<form action="/checkout" method="post" class="row">
|
||||
{% else %}
|
||||
<form action="/checkout?prod={{productName}}&quantity={{quantity}}" method="post" class="row">
|
||||
{% endif %}
|
||||
<div class="col-md-6 mb-5 mb-md-0">
|
||||
<h2 class="h3 mb-3 text-black">Billing Details</h2>
|
||||
<div class="p-3 p-lg-5 border">
|
||||
<div class="form-group">
|
||||
<label for="c_country" class="text-black">Country <span class="text-danger">*</span></label>
|
||||
<label class="text-danger">{{countryError}}</label>
|
||||
<select id="c_country" class="form-control">
|
||||
<option value="1">Select a country</option>
|
||||
<option value="2">bangladesh</option>
|
||||
@ -99,10 +104,12 @@
|
||||
<div class="form-group row">
|
||||
<div class="col-md-6">
|
||||
<label for="c_fname" class="text-black">First Name <span class="text-danger">*</span></label>
|
||||
<label class="text-danger">{{firstNameError}}</label>
|
||||
<input type="text" class="form-control" id="c_fname" name="c_fname">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label for="c_lname" class="text-black">Last Name <span class="text-danger">*</span></label>
|
||||
<label class="text-danger">{{lastNameError}}</label>
|
||||
<input type="text" class="form-control" id="c_lname" name="c_lname">
|
||||
</div>
|
||||
</div>
|
||||
@ -117,6 +124,7 @@
|
||||
<div class="form-group row">
|
||||
<div class="col-md-12">
|
||||
<label for="c_address" class="text-black">Address <span class="text-danger">*</span></label>
|
||||
<label class="text-danger">{{addressError}}</label>
|
||||
<input type="text" class="form-control" id="c_address" name="c_address" placeholder="Street address">
|
||||
</div>
|
||||
</div>
|
||||
@ -128,10 +136,12 @@
|
||||
<div class="form-group row">
|
||||
<div class="col-md-6">
|
||||
<label for="c_state_country" class="text-black">State / Country <span class="text-danger">*</span></label>
|
||||
<label class="text-danger">{{stateError}}</label>
|
||||
<input type="text" class="form-control" id="c_state_country" name="c_state_country">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label for="c_postal_zip" class="text-black">Posta / Zip <span class="text-danger">*</span></label>
|
||||
<label class="text-danger">{{zipError}}</label>
|
||||
<input type="text" class="form-control" id="c_postal_zip" name="c_postal_zip">
|
||||
</div>
|
||||
</div>
|
||||
@ -139,10 +149,12 @@
|
||||
<div class="form-group row mb-5">
|
||||
<div class="col-md-6">
|
||||
<label for="c_email_address" class="text-black">Email Address <span class="text-danger">*</span></label>
|
||||
<label class="text-danger">{{emailError}}</label>
|
||||
<input type="text" class="form-control" id="c_email_address" name="c_email_address">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label for="c_phone" class="text-black">Phone <span class="text-danger">*</span></label>
|
||||
<label class="text-danger">{{phoneError}}</label>
|
||||
<input type="text" class="form-control" id="c_phone" name="c_phone" placeholder="Phone Number">
|
||||
</div>
|
||||
</div>
|
||||
@ -325,7 +337,7 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary btn-lg py-3 btn-block" id="b3">Place Order</button>
|
||||
<button id="b3" class="btn btn-primary btn-lg py-3 btn-block">Place Order</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@ -333,27 +345,11 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!-- </form> -->
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
document.getElementById("b3").onclick = function() {
|
||||
|
||||
document.cookie = "c_country="+document.getElementById("c_country").value;
|
||||
document.cookie = "c_fname="+document.getElementById("c_fname").value;
|
||||
document.cookie = "c_lname="+document.getElementById("c_lname").value;
|
||||
document.cookie = "c_address="+document.getElementById("c_address").value;
|
||||
document.cookie = "c_state_country="+document.getElementById("c_state_country").value;
|
||||
document.cookie = "c_postal_zip="+document.getElementById("c_postal_zip").value;
|
||||
document.cookie = "c_email_address="+document.getElementById("c_email_address").value;
|
||||
document.cookie = "c_phone="+document.getElementById("c_phone").value;
|
||||
if (document.getElementById("c_create_account").checked) {
|
||||
document.cookie = "c_create_account="+document.getElementById("c_create_account").value;
|
||||
}
|
||||
|
||||
window.location.href = '/thankyou';
|
||||
}
|
||||
|
||||
function continueShopping() {
|
||||
window.location.href = '/shop';
|
||||
|
@ -56,4 +56,8 @@ proc removeFromCart*(db: DbConn, cart: Cart) =
|
||||
|
||||
proc updateCart*(db: DbConn, quantity: string, id: int) =
|
||||
## update the quantity of the product in the cart
|
||||
db.exec(sql"UPDATE cart SET quantity=? WHERE id=?", quantity, id)
|
||||
db.exec(sql"UPDATE cart SET quantity=? WHERE id=?", quantity, id)
|
||||
|
||||
proc clearCart*(db: DbConn, userId: int) =
|
||||
## clear the cart of the user
|
||||
db.exec(sql"DELETE FROM cart WHERE user_id=?", userId)
|
@ -25,7 +25,7 @@ proc setupOrders*(db: DbConn) =
|
||||
);
|
||||
""")
|
||||
|
||||
proc createPost*(db: DbConn, order:Orders): int64 =
|
||||
proc createOrder*(db: DbConn, order:Orders): int64 =
|
||||
## createPost creates a new post and returns the id of the new post
|
||||
result = db.insertID(sql"INSERT INTO orders (user_id, country, address, state, postal_code, phone_number, product_id, quantity, order_status, order_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", order.userId, order.country, order.address, order.state, order.postalCode, order.phoneNumber, order.productId, order.quantity, order.orderStatus, order.orderDate)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user