Skip to content

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

Fix getting gross price range when product has no variants

Marcin Gębalaf77a9ca5e232
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 0ed8914b34..65b3ee696e 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -205,6 +205,8 @@ class Product(models.Model, ItemRange, index.Indexed):
def get_gross_price_range(self, **kwargs):
grosses = [self.get_price_per_item(item, **kwargs) for item in self]
+ if not grosses:
+ return None
grosses = sorted(grosses, key=lambda x: x.tax)
return PriceRange(min(grosses), max(grosses))
diff --git a/templates/dashboard/product/product_detail.html b/templates/dashboard/product/product_detail.html
index 1c3843f5d1..1d0d7e5324 100644
--- a/templates/dashboard/product/product_detail.html
+++ b/templates/dashboard/product/product_detail.html
@@ -62,11 +62,15 @@
<p class="text-padding">{% trans "Gross margin" context "Product field" %}</p>
</div>
<div class="col s7 m6">
+ {% if gross_price_range %}
{% with gross_price_range.min_price as min_price %}
{% with gross_price_range.max_price as max_price %}
<p class="text-padding right-align">{% tax min_price %} - {% tax max_price %}</p>
{% endwith %}
{% endwith %}
+ {% else %}
+ <p class="text-padding right-align">-</p>
+ {% endif %}
</div>
</div>
</div>