From 775f32887acd1707ba99dff16358802de94221f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Sun, 11 Feb 2018 18:19:21 +0100 Subject: [PATCH] add art# and Price of all items --- .../webshop/templates/webshop/cart.html | 10 +++- django/didgeridoo/webshop/views.py | 57 +++++++++++++------ 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/django/didgeridoo/webshop/templates/webshop/cart.html b/django/didgeridoo/webshop/templates/webshop/cart.html index be29662..9b6c8a7 100644 --- a/django/didgeridoo/webshop/templates/webshop/cart.html +++ b/django/didgeridoo/webshop/templates/webshop/cart.html @@ -5,17 +5,20 @@ {% if articles_list %} - + + + {% for article in articles_list %} + @@ -25,10 +28,11 @@ {{ article.article.price_in_chf }} {{ currency_name }} + {% endfor %} - diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index 83deedf..ad5e0bb 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -238,6 +238,8 @@ def cart(request): if not 'currency' in request.session: request.session['currency'] = None + else: + currency = request.session['currency'] if request.method == 'POST': currencies_form = CurrenciesForm(request.POST) @@ -254,31 +256,50 @@ def cart(request): cart_id = ShoppingCart.objects.get(user=request.user) except Exception as e: message = "You have no items in the Basket" - if cart_id and request.session['currency']: + + if cart_id: 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) + print(article, idx) + if currency is not None: + article.price_in_chf = rate.exchange( + currency, article.article.price_in_chf) + currency_name = ExchangeRate_name.objects.get(id=currency) + article.price_in_chf = rate.exchange( + currency, + article.price_in_chf) + amount = article.amount + totalprice_of_one = Decimal(amount) * 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) - else: - cart_position = CartPosition.objects.filter(cart=cart_id) - if len(cart_position) > 0: - cart_position_list = list(cart_position) - for idx, cart_position in enumerate(cart_position_list): - prices_in_cart.append(cart_position.article.price_in_chf) - prices_sum = sum(prices_in_cart) - prices_length = len(prices_in_cart) - total = prices_sum / prices_length - articles_list = cart_position_list + + 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) + + total = sum(prices_in_cart) return render(request, 'webshop/cart.html', {'articles_list': articles_list, + 'totalprice_of_one': totalprice_of_one, 'total': total, 'currencies_form': currencies_form, 'article_view': article_view,
IDPOS.ART# NAME STOCK AMOUNTPRICE p.pce. PRICE
{{ article.id }}{{ article.article.id }} - + {{ article.article.name }} {{ totalprice_of_one }}
+ Total: {{ total }}