-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 85774c9
Showing
13 changed files
with
471 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
@app.route('/add', methods=['POST']) | ||
def add_product_to_cart(): | ||
""" | ||
Takes no paramethis inputs, will take inputs from form which adds products to the cart and will then use data from the products database to add costs and book codes | ||
will then also link to the simple payments project to create a checkout when the user checkouts the products. | ||
""" | ||
|
||
cursor = None | ||
try: | ||
_quantity = int(request.form['quantity']) | ||
_code = request.form['code'] | ||
# forms which take input for the quanityt of books being added and adding the books to the cart | ||
|
||
if _quantity and _code and request.method == 'POST': | ||
con = sqlite3.connect('products.db') | ||
cur = con.cursor(); | ||
cur.execute("SELECT * FROM products WHERE code=?;", [_code]) | ||
row = cur.fetchone() | ||
#connects to the product database and look for the product details and then add them to an array | ||
itemArray = { row[2] : {'name' : row[1], 'code' : row[2], 'quantity' : _quantity, 'price' : row[4], 'image' : row[3], 'total_price': _quantity * row[4]}} | ||
print('itemArray is', itemArray) | ||
|
||
all_total_price = 0 | ||
all_total_quantity = 0 | ||
|
||
session.modified = True | ||
|
||
if 'cart_item' in session: | ||
print('in session') | ||
#This will check if the code for the book selected is within the cart and make sure to adjust the quantity depending on how many are added to the cart | ||
if row[2] in session['cart_item']: | ||
for key, value in session['cart_item'].items(): | ||
if row[2] == key: | ||
old_quantity = session['cart_item'][key]['quantity'] | ||
total_quantity = old_quantity + _quantity | ||
session['cart_item'][key]['quantity'] = total_quantity | ||
session['cart_item'][key]['total_price'] = total_quantity * row[4] | ||
else: | ||
session['cart_item'] = array_merge(session['cart_item'], itemArray) | ||
|
||
for key, value in session['cart_item'].items(): | ||
individual_quantity = int(session['cart_item'][key]['quantity']) | ||
individual_price = float(session['cart_item'][key]['total_price']) | ||
all_total_quantity = all_total_quantity + individual_quantity | ||
all_total_price = all_total_price + individual_price | ||
#this will check for the price and adjust the price within the cart | ||
|
||
else: | ||
session['cart_item'] = itemArray | ||
all_total_quantity = all_total_quantity + _quantity | ||
all_total_price = all_total_price + _quantity * row[4] | ||
|
||
session['all_total_quantity'] = all_total_quantity | ||
session['all_total_price'] = all_total_price | ||
|
||
|
||
checksumstr = f"pid={pid:s}&sid={sid:s}&amount={all_total_price:.1f}&token={secret:s}" #this will use the variables sid, pid and the secret token to form the checksum which will form a secure connection to the payment system allowing payments to go through | ||
#print('checksumstr is', checksumstr) | ||
checksum = md5(checksumstr.encode('utf-8')).hexdigest() | ||
session['checksum'] = checksum | ||
#print('checksum is', checksum) | ||
session['sid'] = sid | ||
session['pid'] = pid | ||
|
||
return redirect(url_for('.home')) | ||
else: | ||
return 'Error while adding item to cart' | ||
except Exception as e: | ||
print(e) | ||
finally: | ||
cur.close() | ||
con.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>BookShop - Admin Page</title> | ||
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"> | ||
<link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet" type="text/css" /> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f8f8f8; | ||
margin: 0; | ||
padding: 20px; | ||
} | ||
#admin-header { | ||
background-color: #4CAF50; | ||
color: white; | ||
padding: 10px; | ||
text-align: center; | ||
margin-bottom: 20px; | ||
} | ||
h1 { | ||
margin: 0; | ||
} | ||
#shopping-cart { | ||
background-color: #fff; | ||
padding: 15px; | ||
border-radius: 5px; | ||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); | ||
margin-bottom: 20px; | ||
} | ||
.txt-heading { | ||
font-size: 24px; | ||
margin-bottom: 10px; | ||
} | ||
table { | ||
width: 100%; | ||
border-collapse: collapse; | ||
margin-bottom: 20px; | ||
} | ||
th, td { | ||
padding: 12px; | ||
text-align: left; | ||
border-bottom: 1px solid #ddd; | ||
} | ||
th { | ||
background-color: #f2f2f2; | ||
} | ||
#payment-form { | ||
background-color: #f9f9f9; | ||
padding: 15px; | ||
border-radius: 5px; | ||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); | ||
} | ||
label { | ||
display: block; | ||
margin: 10px 0 5px; | ||
} | ||
input[type="text"], input[type="submit"] { | ||
width: calc(100% - 20px); | ||
padding: 10px; | ||
margin-bottom: 15px; | ||
border: 1px solid #ccc; | ||
border-radius: 4px; | ||
} | ||
input[type="submit"] { | ||
background-color: #4CAF50; | ||
color: white; | ||
border: none; | ||
cursor: pointer; | ||
} | ||
input[type="submit"]:hover { | ||
background-color: #45a049; | ||
} | ||
.product-item { | ||
display: inline-block; | ||
width: 30%; | ||
margin: 1%; | ||
background-color: #fff; | ||
border-radius: 5px; | ||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); | ||
padding: 10px; | ||
text-align: center; | ||
} | ||
.product-title { | ||
font-size: 18px; | ||
margin: 10px 0; | ||
} | ||
.product-price { | ||
font-size: 16px; | ||
color: #333; | ||
} | ||
.btnRemoveAction { | ||
text-decoration: none; | ||
} | ||
.no-records { | ||
text-align: center; | ||
margin: 20px; | ||
font-size: 18px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div> | ||
{% with messages = get_flashed_messages() %} | ||
{% if messages %} | ||
<ul class="flashes"> | ||
{% for message in messages %} | ||
<li>{{ message }}</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
{% endwith %} | ||
</div> | ||
|
||
<!-- Admin Page Heading and Stock Button --> | ||
<div id="admin-header"> | ||
<h1>Administrator Page</h1> | ||
<p><a href="{{url_for('.stocklevel')}}"><button>Stock</button></a></p> | ||
</div> | ||
|
||
<!-- Shopping Cart Section --> | ||
<div id="shopping-cart"> | ||
<div class="txt-heading">Shopping Cart</div> | ||
|
||
{% if 'cart_item' in session %} | ||
<a id="btnEmpty" href="{{ url_for('.empty_cart') }}">Empty Cart</a> | ||
<table class="tbl-cart"> | ||
<tbody> | ||
<tr> | ||
<th>Name</th> | ||
<th>Code</th> | ||
<th style="text-align:right;" width="5%">Quantity</th> | ||
<th style="text-align:right;" width="10%">Unit Price</th> | ||
<th style="text-align:right;" width="10%">Price</th> | ||
<th style="text-align:center;" width="5%">Remove</th> | ||
</tr> | ||
{% for key, val in session['cart_item'].items() %} | ||
{% set quantity = session['cart_item'][key]['quantity'] %} | ||
{% set price = session['cart_item'][key]['price'] %} | ||
{% set item_price = session['cart_item'][key]['total_price'] %} | ||
<tr> | ||
<td><img src="/static/images/{{ session['cart_item'][key]['image'] }}" class="cart-item-image" />{{ session['cart_item'][key]['name'] }}</td> | ||
<td>{{ session['cart_item'][key]['code'] }}</td> | ||
<td style="text-align:right;">{{ quantity }}</td> | ||
<td style="text-align:right;">₤ {{ price }}</td> | ||
<td style="text-align:right;">₤ {{ item_price }}</td> | ||
<td style="text-align:center;"> | ||
<a href="{{ url_for('.delete_product', code=session['cart_item'][key]['code']) }}" class="btnRemoveAction"> | ||
<img src="./images/product-images/product-images/hobbit.jpg/" alt="Remove Item" /> | ||
</a> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
<tr> | ||
<td colspan="2" align="right">Total:</td> | ||
<td align="right">{{ session['all_total_quantity'] }}</td> | ||
<td align="right" colspan="2"><strong>₤ {{ session['all_total_price'] }}</strong></td> | ||
<td></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
<!-- Payment Form --> | ||
<div id="payment-form"> | ||
<h2>Enter Payment Information</h2> | ||
<form action="{{ url_for('checkout') }}" method="POST"> | ||
<label for="card_number">Card Number:</label> | ||
<input type="text" id="card_number" name="card_number" maxlength="16" placeholder="1234 5678 9012 3456" required> | ||
|
||
<label for="expiry_date">Expiry Date:</label> | ||
<input type="text" id="expiry_date" name="expiry_date" placeholder="MM/YY" required> | ||
|
||
<label for="cvv">CVV:</label> | ||
<input type="text" id="cvv" name="cvv" maxlength="3" placeholder="123" required> | ||
|
||
<input type="submit" value="Pay Now"> | ||
<p>Amount to be paid: £ {{ session['all_total_price'] }}</p> | ||
</form> | ||
</div> | ||
|
||
{% else %} | ||
<div class="no-records">Your Cart is Empty</div> | ||
{% endif %} | ||
</div> | ||
|
||
<!-- Product Display Section --> | ||
<div id="product-grid"> | ||
<div class="txt-heading">Products</div> | ||
{% for product in products %} | ||
<div class="product-item"> | ||
<form method="post" action="/add"> | ||
<div><img src="/static/images/{{ product[3] }}" class="product-image"></div> | ||
<div class="product-tile-footer"> | ||
<div class="product-title">{{ product[1] }}</div> | ||
<div class="product-price">£ {{ product[4] }}</div> | ||
<div class="cart-action"> | ||
<input type="hidden" name="code" value="{{ product[2] }}"/> | ||
<input type="text" class="product-quantity" name="quantity" value="1" size="2" /> | ||
<input type="submit" value="Add to Cart" class="btnAddAction" /> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Payment Success</title> | ||
<link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet" type="text/css" /> | ||
</head> | ||
<body> | ||
<div id="payment-success"> | ||
<h1>Payment Successful!</h1> | ||
<p>Thank you for your purchase. Your order has been successfully placed.</p> | ||
<a href="{{ url_for('.home') }}">Return to Home</a> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
423 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Introduction | ||
TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project. | ||
|
||
# Getting Started | ||
TODO: Guide users through getting your code up and running on their own system. In this section you can talk about: | ||
1. Installation process | ||
2. Software dependencies | ||
3. Latest releases | ||
4. API references | ||
|
||
# Build and Test | ||
TODO: Describe and show how to build your code and run the tests. | ||
|
||
# Contribute | ||
TODO: Explain how other users and developers can contribute to make your code better. | ||
|
||
If you want to learn more about creating good readme files then refer the following [guidelines](https://docs.microsoft.com/en-us/azure/devops/repos/git/create-a-readme?view=azure-devops). You can also seek inspiration from the below readme files: | ||
- [ASP.NET Core](https://github.com/aspnet/Home) | ||
- [Visual Studio Code](https://github.com/Microsoft/vscode) | ||
- [Chakra Core](https://github.com/Microsoft/ChakraCore) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The unit testing code for the project |
Oops, something went wrong.