Skip to content

Commit 648e281

Browse files
19 - Checkout Success
1 parent 0ba33ba commit 648e281

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

src/addresses/models.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,14 @@ class Address(models.Model):
1818
postal_code = models.CharField(max_length=120)
1919

2020
def __str__(self):
21-
return str(self.billing_profile)
21+
return str(self.billing_profile)
22+
23+
def get_address(self):
24+
return "{line1}\n{line2}\n{city}\n{state}, {postal}\n{country}".format(
25+
line1 = self.address_line_1,
26+
line2 = self.address_line_2 or "",
27+
city = self.city,
28+
state = self.state,
29+
postal= self.postal_code,
30+
country = self.country
31+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% extends "base.html" %}
2+
3+
4+
{% block content %}
5+
<div class='col-6 mx-auto py-5 text-center'>
6+
<h1 class='display-1'>Thank you for your order!!!</h1>
7+
</div>
8+
9+
{% endblock %}

src/carts/templates/carts/checkout.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@
6565
{% else %}
6666

6767
<h1>Finalize Checkout</h1>
68-
68+
<p>Cart Items: {% for product in object.cart.products.all %}{{ product }}{% if not forloop.last %}, {% endif %}{% endfor %}</p>
69+
<p>Shipping Address: {{ object.shipping_address.get_address }}</p>
70+
<p>Billing Address: {{ object.shipping_address.get_address }}</p>
6971
<p>Cart Total: {{ object.cart.total }}</p>
7072
<p>Shipping Total: {{ object.shipping_total }}</p>
7173
<p>Order Total: {{ object.total }}</p>
7274
<form class='form' method='POST' action="">{% csrf_token %}
73-
<button type='submit'>Checkout</button>
75+
<button type='submit' class='btn btn-success'>Checkout</button>
7476
</form>
7577
{% endif %}
7678
{% endif %}

src/carts/urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
from .views import (
44
cart_home,
55
cart_update,
6-
checkout_home
6+
checkout_home,
7+
checkout_done_view
78
)
89

910
urlpatterns = [
1011
url(r'^$', cart_home, name='home'),
12+
url(r'^checkout/success/$', checkout_done_view, name='success'),
1113
url(r'^checkout/$', checkout_home, name='checkout'),
1214
url(r'^update/$', cart_update, name='update'),
1315
]

src/carts/views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def checkout_home(request):
7070
order_obj.mark_paid()
7171
request.session['cart_items'] = 0
7272
del request.session['cart_id']
73-
return redirect("/cart/success")
73+
return redirect("cart:success")
7474
context = {
7575
"object": order_obj,
7676
"billing_profile": billing_profile,
@@ -87,7 +87,8 @@ def checkout_home(request):
8787

8888

8989

90-
90+
def checkout_done_view(request):
91+
return render(request, "carts/checkout-done.html", {})
9192

9293

9394

src/db.sqlite3

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)