Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Price range templatetag and stock status per size

Artur Smęta5aaea0d5e2f
diff --git a/saleor/product/templates/category/index.html b/saleor/product/templates/category/index.html
index aea5b515a5..4ac04d79f7 100644
--- a/saleor/product/templates/category/index.html
+++ b/saleor/product/templates/category/index.html
@@ -2,6 +2,8 @@
{% load i18n %}
{% load at_size from images %}
{% load slice from shop %}
+{% load price_range from price_ranges %}
+
{% block title %}{{ category }} — {{ block.super }}{% endblock %}
@@ -17,6 +19,8 @@
{% for product in row %}
<div class="col-sm-6">
<h3><a href="{{ product.get_absolute_url }}">{{ product }}</a></h3>
+ <h4>{% price_range product %}</h4>
+
{% if product.images.exists %}
<a href="{{ product.get_absolute_url }}">
<img class="img-responsive" src="{{ product.images.first|at_size:"normal" }}" alt="">
diff --git a/saleor/product/templates/product/_price_range.html b/saleor/product/templates/product/_price_range.html
new file mode 100644
index 0000000000..f8b4c85450
--- /dev/null
+++ b/saleor/product/templates/product/_price_range.html
@@ -0,0 +1,6 @@
+{% load i18n %}
+{% if price_range.min_price == price_range.max_price %}
+ {{ price_range.min_price.gross|floatformat:2 }} {{ price_range.min_price.currency }}
+{% else %}
+ {% trans "Starting from" %} {{ price_range.min_price.gross|floatformat:2 }} {{ price_range.min_price.currency }}
+{% endif %}
\ No newline at end of file
diff --git a/saleor/product/templates/product/details.html b/saleor/product/templates/product/details.html
index 4af335508f..d41cc0ef80 100644
--- a/saleor/product/templates/product/details.html
+++ b/saleor/product/templates/product/details.html
@@ -5,6 +5,7 @@
{% load i18n %}
{% load at_size from images %}
{% load gross from prices %}
+{% load price_range from price_ranges %}
{% block title %}{{ product }} — {{ block.super }}{% endblock %}
@@ -31,6 +32,7 @@
</div>
<div class="col-sm-4">
<p itemprop="offers" itemscope itemtype="http://schema.org/Offer">
+ <span class="price">{% price_range product %}</span>
<span class="price" itemprop="price">{% gross price %}</span>
{% if undiscounted.min_price != price %}
<br>
@@ -40,20 +42,28 @@
{% endif %}
</p>
<p>
+ {% for variant in product.variants.all %}
+ {{ variant.get_size_display }}
{% if product.stock == 0 %}
<link itemprop="availability" href="http://schema.org/OutOfStock" /> <span class="label label-danger">{% trans "Out of stock" %}</span>
{% else %}
<link itemprop="availability" href="http://schema.org/InStock" /> <span class="label label-default">{% trans "In stock" %}</span>
{% endif %}
+ {% endfor %}
</p>
<hr>
- <h3>{% trans "Available Colors" %}</h3>
- {% for collection_product in product.get_products_from_collection %}
- <a href="{{ collection_product.get_absolute_url }}">
- <span class="label" style="background-color: #{{ collection_product.color.color }}">{{ collection_product.color.name }}</span>
- </a>
- {% endfor %}
- <hr>
+ {% with collection=product.get_products_from_collection %}
+ {% if collection %}
+ <h3>{% trans "Available Colors" %}</h3>
+ {% for product in collection %}
+ <a href="{{ product.get_absolute_url }}">
+ <span class="label" style="background-color: #{{ product.color.color }}">{{ product.color.name }}</span>
+ </a>
+ {% endfor %}
+ <hr>
+ {% endif %}
+ {% endwith %}
+
<h3>{% trans "Order" %}</h3>
<form role="form" class="form-vertical" method="post" action=".">
{% csrf_token %}
diff --git a/saleor/product/templatetags/price_ranges.py b/saleor/product/templatetags/price_ranges.py
new file mode 100644
index 0000000000..611c9f74b7
--- /dev/null
+++ b/saleor/product/templatetags/price_ranges.py
@@ -0,0 +1,9 @@
+from django import template
+
+register = template.Library()
+
[email protected]_tag('product/_price_range.html')
+def price_range(product):
+ price_range = product.get_price_range()
+
+ return {'price_range': price_range}
\ No newline at end of file