Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Display products on category page in dashboard
weronka2b0a67bf2f2e
diff --git a/saleor/dashboard/category/views.py b/saleor/dashboard/category/views.pyindex 8b30c60dd4..a6e53af56d 100644--- a/saleor/dashboard/category/views.py+++ b/saleor/dashboard/category/views.py@@ -14,12 +14,16 @@ from .forms import CategoryFormdef category_list(request, root_pk=None):root = Nonepath = None+ products = []categories = Category.tree.root_nodes()if root_pk:+ qs = Category.objects.prefetch_related('products', 'products__main_image')root = get_object_or_404(Category, pk=root_pk)path = root.get_ancestors(include_self=True) if root else []categories = root.get_children()- ctx = {'categories': categories, 'path': path, 'root': root}+ products = sorted(root.products.all(), key=lambda product: product)+ ctx = {'categories': categories, 'path': path, 'root': root,+ 'products': products}return TemplateResponse(request, 'dashboard/category/list.html', ctx)diff --git a/templates/dashboard/category/list.html b/templates/dashboard/category/list.htmlindex d3d206d452..8d67f358c9 100644--- a/templates/dashboard/category/list.html+++ b/templates/dashboard/category/list.html@@ -1,7 +1,9 @@{% extends "dashboard/base.html" %}{% load i18n %}+{% load prices_i18n %}{% load mptt_tags %}{% load materializecss %}+{% load staticfiles %}{% block title %}{% trans "Categories" %} - {{ block.super }}{% endblock %}@@ -117,4 +119,27 @@</ul></div></div>+ {% if products %}+ <div class="row">+ <div class="col s12">+ <h5>Products in this category: {{ products|length }}</h5>+ <ul class="collection list">+ {% for product in products %}+ <li class="collection-item avatar list-item">+ {% if product.images.exists %}+ <img src="{{ product.images.first.image.crop.100x100 }}" alt="" class="circle teal">+ {% else %}+ <img src="{% static 'images/product-image-placeholder-small.png' %}" alt="" class="circle teal">+ {% endif %}+ <a class="title" href="{% url 'dashboard:product-update' pk=product.pk %}">+ <span class="list-item-name">{{ product.name }}</span>+ </a>+ <p class="list-item-price">{% gross product.price %}</p>+ </li>+ {% endfor %}+ </ul>+ {% include "dashboard/includes/_pagination.html" with page_obj=products %}+ </div>+ </div>+ {% endif %}{% endblock %}