From 5220b4d5677da1660c07ee32d687a5caf047291d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Sun, 11 Feb 2018 20:07:18 +0100 Subject: [PATCH] add comments of thaught --- django/didgeridoo/webshop/views.py | 36 +++++++++--------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index 75b6ddd..65fdc05 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -278,7 +278,7 @@ def cart(request): amount = CartForm.ChangeAmount() else: amount = AddToCartForm() - + # if the cart_id is set the user has already added items to cart. try: cart_id = ShoppingCart.objects.get(user=request.user) except Exception as e: @@ -287,40 +287,26 @@ def cart(request): if cart_id: articles = CartPosition.objects.filter(cart=cart_id) articles_list = list(articles) + # scrap out the details to calculate Total of item and Summ of All: for idx, article in enumerate(articles_list): + # only recalculate prices if currency is not CHF: if currency is not None: + # no idea what this does: (!!!) articles_list[idx] = article + # get price of item in CHF: article.price_in_chf = rate.exchange( currency, article.article.price_in_chf) + # get currencyname to display: currency_name = ExchangeRate_name.objects.get(id=currency) + # get exchange_rate multiplyed: article.price_in_chf = rate.exchange( currency, article.price_in_chf) - amount = article.amount - totalprice_of_one = Decimal(amount) * article.article.price_in_chf - + # calculate item * price for one row in cart: + totalprice_of_one = Decimal(article.amount) * article.article.price_in_chf + # add to a list of total prices per item prices_in_cart.append(article.article.price_in_chf) - - # if cart_id and request.session['currency']: - # articles = CartPosition.objects.filter(cart=cart_id) - # articles_list = list(articles) - # currency = request.session['currency'] - # for idx, article in enumerate(articles_list): - # article.price_in_chf = rate.exchange( - # currency, article.article.price_in_chf) - # articles_list[idx] = article - # currency_name = ExchangeRate_name.objects.get(id=currency) - # article.price_in_chf = rate.exchange( - # currency, - # article.price_in_chf) - # prices_in_cart.append(article.article.price_in_chf) - # - # if cart_id: - # articles = CartPosition.objects.filter(cart=cart_id) - # articles_list = list(articles) - # for idx, article in enumerate(articles_list): - # prices_in_cart.append(article.article.price_in_chf) - + # sum the list of totalprices of items to a summ of all items in cart. total = sum(prices_in_cart) return render(request, 'webshop/cart.html',