Skip to content

Commit

Permalink
5 - Checkout View
Browse files Browse the repository at this point in the history
  • Loading branch information
codingforentrepreneurs committed Sep 28, 2017
1 parent 00a2b87 commit 40e7c81
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/carts/templates/carts/checkout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "base.html" %}


{% block content %}
<h1>Checkout</h1>

<p>Cart Total: {{ object.cart.total }}</p>
<p>Shipping Total: {{ object.shipping_total }}</p>
<p>Order Total: {{ object.total }}</p>



{% endblock %}
5 changes: 5 additions & 0 deletions src/carts/templates/carts/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ <h1>Cart</h1>
<td colspan="2"></td>
<td><b>Total</b> {{ cart.total }}</td>
</tr>
<tr>
<td colspan="2"></td>
<td><a class='btn btn-lg btn-success' href='{% url "cart:checkout" %}'>Checkout</a></td>
</tr>

</tbody>
</table>

Expand Down
2 changes: 2 additions & 0 deletions src/carts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
from .views import (
cart_home,
cart_update,
checkout_home
)

urlpatterns = [
url(r'^$', cart_home, name='home'),
url(r'^checkout/$', checkout_home, name='checkout'),
url(r'^update/$', cart_update, name='update'),
]

23 changes: 22 additions & 1 deletion src/carts/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.shortcuts import render, redirect

from orders.models import Order
from products.models import Product
from .models import Cart

Expand All @@ -23,4 +24,24 @@ def cart_update(request):
cart_obj.products.add(product_obj) # cart_obj.products.add(product_id)
request.session['cart_items'] = cart_obj.products.count()
# return redirect(product_obj.get_absolute_url())
return redirect("cart:home")
return redirect("cart:home")



def checkout_home(request):
cart_obj, cart_created = Cart.objects.new_or_get(request)
order_obj = None
if cart_created or cart_obj.products.count() == 0:
return redirect("cart:home")
else:
order_obj, new_order_obj = Order.objects.get_or_create(cart=cart_obj)
return render(request, "carts/checkout.html", {"object": order_obj})









Binary file modified src/db.sqlite3
Binary file not shown.

0 comments on commit 40e7c81

Please sign in to comment.