Skip to content

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

Display first product category in breadcrumbs in details view

Marcin Gębala400486370093
diff --git a/saleor/product/models/base.py b/saleor/product/models/base.py
index 567ea35247..641d4cdf3c 100644
--- a/saleor/product/models/base.py
+++ b/saleor/product/models/base.py
@@ -138,6 +138,9 @@ class Product(models.Model, ItemRange):
def is_in_stock(self):
return any(variant.is_in_stock() for variant in self)
+ def get_first_category(self):
+ return self.categories.filter(hidden=False).first()
+
@python_2_unicode_compatible
class ProductVariant(models.Model, Item):
diff --git a/saleor/product/templates/product/details.html b/saleor/product/templates/product/details.html
index 0ccb2a99bd..dbb04c738e 100644
--- a/saleor/product/templates/product/details.html
+++ b/saleor/product/templates/product/details.html
@@ -11,7 +11,11 @@
{% block breadcrumb %}
{{ block.super }}
- <li><a href="{{ product.category.get_absolute_url }}">{{ product.category }}</a></li>
+ {% with product.get_first_category as category %}
+ {% if category %}
+ <li><a href="{{ category.get_absolute_url }}">{{ category }}</a></li>
+ {% endif %}
+ {% endwith %}
<li><a href="{{ product.get_absolute_url }}">{{ product }}</a></li>
{% endblock breadcrumb %}