031
This commit is contained in:
		
							parent
							
								
									31056a9246
								
							
						
					
					
						commit
						b5b52e8be0
					
				
							
								
								
									
										
											BIN
										
									
								
								db5.sqlite3
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								db5.sqlite3
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										76
									
								
								src/a3.nim
									
									
									
									
									
								
							
							
						
						
									
										76
									
								
								src/a3.nim
									
									
									
									
									
								
							| @ -6,7 +6,7 @@ import | |||||||
|   strutils, |   strutils, | ||||||
|   strformat, |   strformat, | ||||||
|   ./a3pkg/[models, mics], |   ./a3pkg/[models, mics], | ||||||
|   ./a3c/[products, users, cart] |   ./a3c/[products, users, cart, orders] | ||||||
| 
 | 
 | ||||||
| "/" -> [get, post]: | "/" -> [get, post]: | ||||||
| 
 | 
 | ||||||
| @ -193,6 +193,7 @@ import | |||||||
|     zipError = "" |     zipError = "" | ||||||
|     emailError = "" |     emailError = "" | ||||||
|     phoneError = "" |     phoneError = "" | ||||||
|  |     ch = "" | ||||||
| 
 | 
 | ||||||
|   try: |   try: | ||||||
|     email = ctx.cookies["email"] |     email = ctx.cookies["email"] | ||||||
| @ -225,6 +226,7 @@ import | |||||||
|     ca.quantity = quantity |     ca.quantity = quantity | ||||||
|     products.add(product) |     products.add(product) | ||||||
|     cart.add(ca) |     cart.add(ca) | ||||||
|  |     ch = "d" | ||||||
| 
 | 
 | ||||||
|   else: |   else: | ||||||
|     var |     var | ||||||
| @ -257,6 +259,8 @@ import | |||||||
|     zipError = "" |     zipError = "" | ||||||
|     emailError = "" |     emailError = "" | ||||||
|     phoneError = "" |     phoneError = "" | ||||||
|  |     passwordError = "" | ||||||
|  |     ch = "" | ||||||
| 
 | 
 | ||||||
|   try: |   try: | ||||||
|     email = ctx.cookies["email"] |     email = ctx.cookies["email"] | ||||||
| @ -272,9 +276,6 @@ import | |||||||
|     productName = "" |     productName = "" | ||||||
|     quantity = 0 |     quantity = 0 | ||||||
| 
 | 
 | ||||||
|   if email != "": |  | ||||||
|     productCount = micsCartProductCount(email, password) |  | ||||||
| 
 |  | ||||||
|   # if productName == "" and email == "": |   # if productName == "" and email == "": | ||||||
|     # ctx.redirect("/login") |     # ctx.redirect("/login") | ||||||
| 
 | 
 | ||||||
| @ -287,52 +288,60 @@ import | |||||||
|     zip = cookies["c_postal_zip"] |     zip = cookies["c_postal_zip"] | ||||||
|     email1 = cookies["c_email_address"] |     email1 = cookies["c_email_address"] | ||||||
|     phone = cookies["c_phone"] |     phone = cookies["c_phone"] | ||||||
|  |     password1: string | ||||||
|  | 
 | ||||||
|  |   echo cookies | ||||||
|  | 
 | ||||||
|  |   try: | ||||||
|  |     password1 = cookies["password"] | ||||||
|  |   except: | ||||||
|  |     password1 = "" | ||||||
| 
 | 
 | ||||||
|   if country == "": countryError = "Country is Required" |   if country == "": countryError = "Country is Required" | ||||||
| 
 |  | ||||||
|   if firstName == "": firstNameError = "First Name is Required" |   if firstName == "": firstNameError = "First Name is Required" | ||||||
| 
 |  | ||||||
|   if lastName == "": lastNameError = "Last Name is Required" |   if lastName == "": lastNameError = "Last Name is Required" | ||||||
| 
 |  | ||||||
|   if address == "": addressError = "Address is Required" |   if address == "": addressError = "Address is Required" | ||||||
| 
 |  | ||||||
|   if state == "": stateError = "State is Required" |   if state == "": stateError = "State is Required" | ||||||
| 
 |  | ||||||
|   if zip == "": zipError = "Zip is Required" |   if zip == "": zipError = "Zip is Required" | ||||||
| 
 |  | ||||||
|   if email1 == "": emailError = "Email is Required" |   if email1 == "": emailError = "Email is Required" | ||||||
| 
 |  | ||||||
|   if phone == "": phoneError = "Phone is Required" |   if phone == "": phoneError = "Phone is Required" | ||||||
| 
 | 
 | ||||||
|   # if countryError == "" and firstNameError == "" and lastNameError == "" and addressError == "" and stateError == "" and zipError == "" and emailError == "" and phoneError == "": |   if email != "": | ||||||
|   #   var |     productCount = micsCartProductCount(email, password) | ||||||
|   #     userId = db.getUserId(email, password) |  | ||||||
|   #     cart = db.getUserCart(userId) |  | ||||||
|   #     order: Order |  | ||||||
| 
 | 
 | ||||||
|   #   order.userId = userId |   if countryError == "" and firstNameError == "" and lastNameError == "" and addressError == "" and stateError == "" and zipError == "" and emailError == "" and phoneError == "": | ||||||
|   #   order.country = country |     var | ||||||
|   #   order.firstName = firstName |       userId = db.getUserId(email, password) | ||||||
|   #   order.lastName = lastName |       cart = db.getUserCart(userId) | ||||||
|   #   order.address = address |       order: Orders | ||||||
|   #   order.state = state |       user: User | ||||||
|   #   order.zip = zip |  | ||||||
|   #   order.email = email1 |  | ||||||
|   #   order.phone = phone |  | ||||||
| 
 | 
 | ||||||
|   #   db.createOrder(order) |     order.userId = userId | ||||||
|  |     order.country = country | ||||||
|  |     order.address = address | ||||||
|  |     order.state = state | ||||||
|  |     order.postalCode = zip | ||||||
|  |     order.phoneNumber = phone | ||||||
| 
 | 
 | ||||||
|   #   for c, d in cart: |     user.firstName = firstName | ||||||
|   #     var product = db.getProductById(d.productId) |     user.lastName = lastName | ||||||
|   #     products.add(product) |     user.email = email1 | ||||||
| 
 | 
 | ||||||
|   #   db.clearCart(userId) |     if email == "": | ||||||
|  |       user.password = password1 | ||||||
|  |       user.accessLevel = 1 | ||||||
|  |       db.createPost(user) | ||||||
|  |       db.clearCart(userId) | ||||||
| 
 | 
 | ||||||
|   #   compileTemplateFile(getScriptDir() / "a3a" / "thankyou.nimja") |     var _ = db.createOrder(order) | ||||||
| 
 | 
 | ||||||
|   # else: |     for c, d in cart: | ||||||
|   #   compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja") |       var product = db.getProductById(d.productId) | ||||||
|  |       products.add(product) | ||||||
| 
 | 
 | ||||||
|  |     compileTemplateFile(getScriptDir() / "a3a" / "thankyou.nimja") | ||||||
|  | 
 | ||||||
|  |   else: | ||||||
|     if productName != "": |     if productName != "": | ||||||
|       var |       var | ||||||
|         product: Products |         product: Products | ||||||
| @ -352,7 +361,6 @@ 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") | ||||||
|  | |||||||
| @ -77,12 +77,17 @@ | |||||||
|           </div> |           </div> | ||||||
|         </div> |         </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"> |         <div class="col-md-6 mb-5 mb-md-0"> | ||||||
|           <h2 class="h3 mb-3 text-black">Billing Details</h2> |           <h2 class="h3 mb-3 text-black">Billing Details</h2> | ||||||
|           <div class="p-3 p-lg-5 border"> |           <div class="p-3 p-lg-5 border"> | ||||||
|             <div class="form-group"> |             <div class="form-group"> | ||||||
|               <label for="c_country" class="text-black">Country <span class="text-danger">*</span></label> |               <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"> |               <select id="c_country" class="form-control"> | ||||||
|                 <option value="1">Select a country</option>     |                 <option value="1">Select a country</option>     | ||||||
|                 <option value="2">bangladesh</option>     |                 <option value="2">bangladesh</option>     | ||||||
| @ -99,10 +104,12 @@ | |||||||
|             <div class="form-group row"> |             <div class="form-group row"> | ||||||
|               <div class="col-md-6"> |               <div class="col-md-6"> | ||||||
|                 <label for="c_fname" class="text-black">First Name <span class="text-danger">*</span></label> |                 <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"> |                 <input type="text" class="form-control" id="c_fname" name="c_fname"> | ||||||
|               </div> |               </div> | ||||||
|               <div class="col-md-6"> |               <div class="col-md-6"> | ||||||
|                 <label for="c_lname" class="text-black">Last Name <span class="text-danger">*</span></label> |                 <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"> |                 <input type="text" class="form-control" id="c_lname" name="c_lname"> | ||||||
|               </div> |               </div> | ||||||
|             </div> |             </div> | ||||||
| @ -117,6 +124,7 @@ | |||||||
|             <div class="form-group row"> |             <div class="form-group row"> | ||||||
|               <div class="col-md-12"> |               <div class="col-md-12"> | ||||||
|                 <label for="c_address" class="text-black">Address <span class="text-danger">*</span></label> |                 <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"> |                 <input type="text" class="form-control" id="c_address" name="c_address" placeholder="Street address"> | ||||||
|               </div> |               </div> | ||||||
|             </div> |             </div> | ||||||
| @ -128,10 +136,12 @@ | |||||||
|             <div class="form-group row"> |             <div class="form-group row"> | ||||||
|               <div class="col-md-6"> |               <div class="col-md-6"> | ||||||
|                 <label for="c_state_country" class="text-black">State / Country <span class="text-danger">*</span></label> |                 <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"> |                 <input type="text" class="form-control" id="c_state_country" name="c_state_country"> | ||||||
|               </div> |               </div> | ||||||
|               <div class="col-md-6"> |               <div class="col-md-6"> | ||||||
|                 <label for="c_postal_zip" class="text-black">Posta / Zip <span class="text-danger">*</span></label> |                 <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"> |                 <input type="text" class="form-control" id="c_postal_zip" name="c_postal_zip"> | ||||||
|               </div> |               </div> | ||||||
|             </div> |             </div> | ||||||
| @ -139,10 +149,12 @@ | |||||||
|             <div class="form-group row mb-5"> |             <div class="form-group row mb-5"> | ||||||
|               <div class="col-md-6"> |               <div class="col-md-6"> | ||||||
|                 <label for="c_email_address" class="text-black">Email Address <span class="text-danger">*</span></label> |                 <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"> |                 <input type="text" class="form-control" id="c_email_address" name="c_email_address"> | ||||||
|               </div> |               </div> | ||||||
|               <div class="col-md-6"> |               <div class="col-md-6"> | ||||||
|                 <label for="c_phone" class="text-black">Phone <span class="text-danger">*</span></label> |                 <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"> |                 <input type="text" class="form-control" id="c_phone" name="c_phone" placeholder="Phone Number"> | ||||||
|               </div> |               </div> | ||||||
|             </div> |             </div> | ||||||
| @ -325,7 +337,7 @@ | |||||||
|                 </div> |                 </div> | ||||||
| 
 | 
 | ||||||
|                 <div class="form-group"> |                 <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> | ||||||
| 
 | 
 | ||||||
|               </div> |               </div> | ||||||
| @ -333,27 +345,11 @@ | |||||||
|           </div> |           </div> | ||||||
| 
 | 
 | ||||||
|         </div> |         </div> | ||||||
|       </div> |       </form> | ||||||
|       <!-- </form> --> |       <!-- </form> --> | ||||||
|     </div> |     </div> | ||||||
|   </div> |   </div> | ||||||
|   <script> |   <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() { |     function continueShopping() { | ||||||
|       window.location.href = '/shop'; |       window.location.href = '/shop'; | ||||||
|  | |||||||
| @ -57,3 +57,7 @@ proc removeFromCart*(db: DbConn, cart: Cart) = | |||||||
| proc updateCart*(db: DbConn, quantity: string, id: int) = | proc updateCart*(db: DbConn, quantity: string, id: int) = | ||||||
|   ## update the quantity of the product in the cart |   ## 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 |   ## 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) |   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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user