Skip to content
Snippets Groups Projects
Commit 92e86ed5 authored by Michael Drury's avatar Michael Drury
Browse files

added add to cart on wishlist which removes from wishlist and adds to cart

parent 5f934ba8
No related branches found
No related tags found
No related merge requests found
...@@ -187,7 +187,8 @@ def wishlist(): ...@@ -187,7 +187,8 @@ def wishlist():
wishlist_id_list = make_lists_out[1] wishlist_id_list = make_lists_out[1]
# performs the functionality of the remove from wishlist form. It does it in the same was as the cart does but have # performs the functionality of the remove from wishlist form. It does it in the same was as the cart does but have
# to repeat code as does it on different columns # to repeat code as does it on different columns also if added to cart the removes from wishlist aswell using the
# remove from wishlist function
remove_form = removeFormWishlist() remove_form = removeFormWishlist()
if remove_form.validate_on_submit(): if remove_form.validate_on_submit():
...@@ -199,18 +200,31 @@ def wishlist(): ...@@ -199,18 +200,31 @@ def wishlist():
return redirect(url_for('wishlist')) return redirect(url_for('wishlist'))
elif request.method == 'POST': elif request.method == 'POST':
remove_id = request.form['remove_id'] try:
wishlist_id_list.remove(remove_id) remove_id = request.form['remove_id']
new_wishlist_string = '' remove_from_wishlist(remove_id)
for item_id in wishlist_id_list: except:
new_wishlist_string = new_wishlist_string + item_id + ' ' item_to_add_cart = request.form['item_id_cart']
for user in db.session.query(User).filter_by(id=current_user.get_id()): for user_row in db.session.query(User).filter_by(id=current_user.get_id()):
user.wishlist = new_wishlist_string user_row.cart = user_row.cart + item_to_add_cart + ' '
db.session.commit() remove_from_wishlist(item_to_add_cart)
db.session.commit()
return redirect(url_for('wishlist')) return redirect(url_for('wishlist'))
return render_template('wishlist.html', wishlist_list = wishlist_list, wishlist_size = len(wishlist_list), remove_form = remove_form) return render_template('wishlist.html', wishlist_list = wishlist_list, wishlist_size = len(wishlist_list), remove_form = remove_form)
# works very similarly to removing from cart on cart page
def remove_from_wishlist(item_id):
make_lists_out = make_lists(current_user.wishlist)
wishlist_id_list = make_lists_out[1]
wishlist_id_list.remove(item_id)
new_wishlist_string = ''
for item_id in wishlist_id_list:
new_wishlist_string = new_wishlist_string + item_id + ' '
for user in db.session.query(User).filter_by(id=current_user.get_id()):
user.wishlist = new_wishlist_string
db.session.commit()
@app.route('/item', methods=['GET', 'POST']) @app.route('/item', methods=['GET', 'POST'])
def item_page(): def item_page():
......
...@@ -242,7 +242,7 @@ li { ...@@ -242,7 +242,7 @@ li {
margin-left: 2%; margin-left: 2%;
margin-bottom: 20px; margin-bottom: 20px;
padding: 10px; padding: 10px;
height: 150px height: 180px
} }
.cart_box:hover { .cart_box:hover {
...@@ -354,6 +354,8 @@ li { ...@@ -354,6 +354,8 @@ li {
.login_field { .login_field {
font-size: 1.5vw; font-size: 1.5vw;
padding: 0px;
margin: 0px;
} }
.thank_you_tick { .thank_you_tick {
......
...@@ -36,10 +36,14 @@ ...@@ -36,10 +36,14 @@
<img class = "item_cart_img" src = "{{ url_for('static', filename='images/' + item.product_image) }}" alt="product image"/></a> <img class = "item_cart_img" src = "{{ url_for('static', filename='images/' + item.product_image) }}" alt="product image"/></a>
<p><a class = "item_shopping_name" href="/item?id={{item.product_id}}"><b>{{ item.product_name }}</b></a></p> <p><a class = "item_shopping_name" href="/item?id={{item.product_id}}"><b>{{ item.product_name }}</b></a></p>
<p class = "shopping_item_text">price: £{{ item.product_price }}</p> <p class = "shopping_item_text">price: £{{ item.product_price }}</p>
<form method = "post" style = "padding-top: 10px"> <form method = "post">
<input type = "hidden" name = "remove_id" value = {{ item.product_id }}> <input type = "hidden" name = "remove_id" value = {{ item.product_id }}>
<input class = "orange_button" type = "submit" value = "remove"> <input class = "orange_button" type = "submit" value = "remove">
</form> </form>
<form method = "post" style = "padding-top: 10px">
<input type = "hidden" name = "item_id_cart" value = {{ item.product_id }}>
<input class = "orange_button" type = "submit" value = "add to cart">
</form>
</div> </div>
{% endfor %} {% endfor %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment