Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Use pricing info on list and detail views
Artur Smęt35f1136fb6c6
diff --git a/saleor/product/templatetags/product_tags.py b/saleor/product/templatetags/product_tags.pynew file mode 100644index 0000000000..6359844bd9--- /dev/null+++ b/saleor/product/templatetags/product_tags.py@@ -0,0 +1,9 @@+from django import template+from ..utils import get_pricing_info++register = template.Library()+++def pricing_info_for_product(product, discounts=None, local_currency=None):+ return get_pricing_info(product, discounts, local_currency)diff --git a/saleor/product/views.py b/saleor/product/views.pyindex 7843fb579d..85740c95a0 100644--- a/saleor/product/views.py+++ b/saleor/product/views.py@@ -11,7 +11,8 @@ from ..cart.decorators import get_cart_from_requestfrom ..core.utils import get_paginator_items, to_local_currencyfrom .forms import get_form_class_for_productfrom .models import Category-from .utils import products_with_details, get_product_images+from .utils import (products_with_details,+ get_pricing_info, get_product_images)def product_details(request, slug, product_id):@@ -61,14 +62,8 @@ def product_details(request, slug, product_id):form.save()return redirect('cart:index')- # price handling- price_range = product.get_price_range(discounts=request.discounts)- undiscounted_price_range = product.get_price_range()- if undiscounted_price_range.min_price > price_range.min_price:- discount = undiscounted_price_range.min_price - price_range.min_price- else:- discount = None- local_price_range = to_local_currency(price_range, request.currency)+ pricing_info = get_pricing_info(product, discounts=request.discounts,+ local_currency=request.currency)template_name = 'product/details_%s.html' % (type(product).__name__.lower(),)@@ -77,14 +72,11 @@ def product_details(request, slug, product_id):return TemplateResponse(request, templates,{- 'discount': discount,+ 'pricing_info': pricing_info,+ 'product_images': product_images,'form': form,'is_visible': is_visible,- 'local_price_range': local_price_range,- 'price_range': price_range,- 'product': product,- 'undiscounted_price_range': undiscounted_price_range,- 'product_images': product_images})+ 'product': product})def category_index(request, path, category_id):diff --git a/templates/category/_items.html b/templates/category/_items.htmlindex dcf40c7061..8dbaf9473b 100644--- a/templates/category/_items.html+++ b/templates/category/_items.html@@ -2,6 +2,7 @@{% load staticfiles %}{% load price_range from price_ranges %}{% load discounted_price_range price_difference from discount %}+{% load pricing_info_for_product from product_tags %}{% load product_first_image from product_images %}{% for product in products %}@@ -16,14 +17,11 @@<div class="panel-footer">{% if product.is_in_stock %}- {% with price_range=product|discounted_price_range:request.discounts undiscounted=product.get_price_range %}- {% with discount=undiscounted.min_price|price_difference:price_range.min_price %}- {% price_range price_range %}- {% if undiscounted.min_price != price_range.min_price %}- <span class="label label-success">{% trans "Discount!" %}</span>- {% endif %}- {% endwith %}- {% endwith %}+ {% pricing_info_for_product product request.discounts as pricing_info %}+ {% price_range pricing_info.price_range %}+ {% if pricing_info.discount %}+ <span class="label label-success">{% trans "Discount!" %}</span>+ {% endif %}{% else %} {% endif %}diff --git a/templates/product/details.html b/templates/product/details.htmlindex 338eb670b4..a762d40fe4 100644--- a/templates/product/details.html+++ b/templates/product/details.html@@ -35,15 +35,15 @@{% if product.is_in_stock %}<p class="lead" itemprop="offers" itemscope itemtype="http://schema.org/Offer">- <span class="price">{% price_range price_range %}</span>- {% if discount %}- <small class="price undiscounted text-muted">{% gross undiscounted_price_range.min_price html=True %}</small>+ <span class="price">{% price_range pricing_info.price_range %}</span>+ {% if pricing_info.discount %}+ <small class="price undiscounted text-muted">{% gross pricing_info.undiscounted_price_range.min_price html=True %}</small>{% endif %}- {% if local_price_range %}+ {% if pricing_info.price_range_local_currency %}<br><small class="text-info">≈- {% gross local_price_range.min_price html=True %}+ {% gross pricing_info.price_range_local_currency.min_price html=True %}</small>{% endif %}</p>