Skip to content

Commit 6b37376

Browse files
committed
Add sourcecode for shopping bag bug fix.
1 parent 276db59 commit 6b37376

327 files changed

Lines changed: 7100 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

21-shopping-bag-bug-fix/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.venv
2+
*sqlite3
3+
*.pyc
4+
__pycache__
5+
env
6+
env.py

21-shopping-bag-bug-fix/Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: gunicorn boutique_ado.wsgi:application

21-shopping-bag-bug-fix/README.md

574 Bytes

boutique_ado_v1

Bugfix changes are in the following files, please read the comments in the code for details of the changes.

  • bag/templates/bag/quantity-form.html
  • products/templates/products/includes/quantity_input_script.html
  • products/templates/products/product_detail.html

21-shopping-bag-bug-fix/bag/__init__.py

Whitespace-only changes.

21-shopping-bag-bug-fix/bag/admin.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class BagConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'bag'
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from decimal import Decimal
2+
from django.conf import settings
3+
from django.shortcuts import get_object_or_404
4+
from products.models import Product
5+
6+
7+
def bag_contents(request):
8+
9+
bag_items = []
10+
total = 0
11+
product_count = 0
12+
bag = request.session.get('bag', {})
13+
14+
for item_id, item_data in bag.items():
15+
16+
if isinstance(item_data, int):
17+
product = get_object_or_404(Product, pk=item_id)
18+
total += item_data * product.price
19+
product_count += item_data
20+
bag_items.append({
21+
'item_id': item_id,
22+
'quantity': item_data,
23+
'product': product,
24+
})
25+
26+
else:
27+
product = get_object_or_404(Product, pk=item_id)
28+
for size, quantity in item_data['items_by_size'].items():
29+
total += quantity * product.price
30+
product_count += quantity
31+
bag_items.append({
32+
'item_id': item_id,
33+
'quantity': quantity,
34+
'product': product,
35+
'size': size,
36+
})
37+
38+
if total < settings.FREE_DELIVERY_THRESHOLD:
39+
delivery = total * Decimal(settings.STANDARD_DELIVERY_PERCENTAGE / 100)
40+
free_delivery_delta = settings.FREE_DELIVERY_THRESHOLD - total
41+
else:
42+
delivery = 0
43+
free_delivery_delta = 0
44+
45+
grand_total = delivery + total
46+
47+
context = {
48+
'bag_items': bag_items,
49+
'total': total,
50+
'product_count': product_count,
51+
'delivery': delivery,
52+
'free_delivery_delta': free_delivery_delta,
53+
'free_delivery_threshold': settings.FREE_DELIVERY_THRESHOLD,
54+
'grand_total': grand_total,
55+
}
56+
57+
return context

21-shopping-bag-bug-fix/bag/migrations/__init__.py

Whitespace-only changes.

21-shopping-bag-bug-fix/bag/models.py

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<h6><strong>Bag Total: ${{ total|floatformat:2 }}</strong></h6>
2+
<h6>Delivery: ${{ delivery|floatformat:2 }}</h6>
3+
<h4 class="mt-4"><strong>Grand Total: ${{ grand_total|floatformat:2 }}</strong></h4>
4+
{% if free_delivery_delta > 0 %}
5+
<p class="mb-1 text-danger">
6+
You could get free delivery by spending just <strong>${{ free_delivery_delta }}</strong> more!
7+
</p>
8+
{% endif %}

0 commit comments

Comments
 (0)