Skip to content

Commit

Permalink
fix cart function redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
kritserv committed Oct 2, 2023
1 parent 98523b0 commit 27c45ed
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions code/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ def add_to_cart(request, title):
order_item.quantity += 1
order_item.save()
messages.info(request, "This item quality from your cart was updated.")
return redirect("view_product_computer", id=Computer.objects.get(title=title).id)
return redirect(request.META.get('HTTP_REFERER'))
else:
order_item = OrderProductItem.objects.create(prod_item=prod_item, user=request.user, ordered=False)
order.items.add(order_item)
messages.info(request, "This item was added to your cart.")
return redirect("view_product_computer", id=Computer.objects.get(title=title).id)
return redirect(request.META.get('HTTP_REFERER'))
else:
ordered_date = timezone.now()
order = Order.objects.create(user=request.user, ordered_date=ordered_date)
order_item = OrderProductItem.objects.create(prod_item=prod_item, user=request.user, ordered=False)
order.items.add(order_item)
messages.info(request, "This item was added to from your cart.")
return redirect("view_product_computer", id=Computer.objects.get(title=title).id)
return redirect(request.META.get('HTTP_REFERER'))

@login_required
def remove_from_cart(request, title):
Expand All @@ -79,13 +79,13 @@ def remove_from_cart(request, title):
order.items.remove(order_item)
order_item.delete()
messages.info(request, "This item was removed from your cart.")
return redirect("view_product_computer", id=Computer.objects.get(title=title).id)
return redirect(request.META.get('HTTP_REFERER'))
else:
messages.info(request, "This item was not in your cart")
return redirect("view_product_computer", id=Computer.objects.get(title=title).id)
return redirect(request.META.get('HTTP_REFERER'))
else:
messages.info(request, "You do not have an active order")
return redirect("view_product_computer", id=Computer.objects.get(title=title).id)
return redirect(request.META.get('HTTP_REFERER'))


@login_required
Expand All @@ -102,14 +102,14 @@ def remove_single_item_from_cart(request, title):
order_item.quantity -= 1
order_item.save()
messages.info(request, "This item quantity was updated.")
return redirect("view_product_computer", id=Computer.objects.get(title=title).id)
return redirect(request.META.get('HTTP_REFERER'))
else:
order.items.remove(order_item)
messages.info(request, "This item quantity was updated.")
return redirect("view_product_computer", id=Computer.objects.get(title=title).id)
return redirect(request.META.get('HTTP_REFERER'))
else:
messages.info(request, "This item was not in your cart")
return redirect("view_product_computer", id=Computer.objects.get(title=title).id)
return redirect(request.META.get('HTTP_REFERER'))
else:
messages.info(request, "You do not have an active order")
return redirect("view_product_computer", id=Computer.objects.get(title=title).id)
return redirect(request.META.get('HTTP_REFERER'))

0 comments on commit 27c45ed

Please sign in to comment.