아래의 코드 추가
{% endfor %}
<h3 class="text-center">Total: {{ totals }}</h3>
<br />
<br />
<br />
{% else %} There's Nothing in your cart {% endif %}
def cart_summary(request):
(... 생략 ...)
totals = cart.cart_total()
return render(request, "cart/cart_summary.html",{"cart_products": cart_products,"quantities": quantities,"totals": totals})
def cart_total(self):
product_ids = self.cart.keys()
products = Product.objects.filter(id__in=product_ids)
quantities = self.cart
total = 0
for key, value in quantities.items():
#Convert key string into so we
key = int(key)
for product in products:
if product.id == key:
if product.is_sale:
total = total + (product.sale_price * value)
else:
total = total + (product.price * value)
return total
아래와 같이 나오는지 확인
