Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Improve category index view
Paweł Kowalewski34e833327c21
diff --git a/saleor/product/templates/category/_items.html b/saleor/product/templates/category/_items.htmlnew file mode 100644index 0000000000..8b2519fdfe--- /dev/null+++ b/saleor/product/templates/category/_items.html@@ -0,0 +1,36 @@+{% load i18n %}+{% load staticfiles %}+{% load price_range from price_ranges %}+{% load discounted_price_range price_difference from discount %}++{% for product in products %}+ <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3" itemscope itemtype="https://schema.org/Product">+ <div class="panel panel-default text-center">+ <div class="panel-body">+ <a itemprop="url" href="{{ product.get_absolute_url }}">+ {% if product.images.first %}+ <img itemprop="image" class="img-responsive" src="{{ product.images.first.image.crop.400x400 }}" alt="">+ {% else %}+ <img src="{% static 'images/product-image-placeholder.png' %}" alt="" class="img-responsive">+ {% endif %}+ <span class="product-list-item-name" itemprop="name" title="{{ product }}">{{ product }}</span>+ </a>+ </div>++ <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 %}+ {% else %}+ + {% endif %}+ </div>+ </div>+ </div>+{% endfor %}diff --git a/saleor/product/templates/category/index.html b/saleor/product/templates/category/index.htmlindex 4688c843ba..6dae47d9b5 100644--- a/saleor/product/templates/category/index.html+++ b/saleor/product/templates/category/index.html@@ -1,45 +1,44 @@{% extends "base.html" %}-{% load i18n %}{% load slice from shop %}-{% load price_range from price_ranges %}-{% load discounted_price_range price_difference from discount %}{% load static from staticfiles %}{% block title %}{{ category }} — {{ block.super }}{% endblock %}{% block breadcrumb %}{{ block.super }}- <li><a href="{{ category.get_absolute_url }}">{{ category }}</a></li>+ {% for breadcrumb in breadcrumbs %}+ <li{% if forloop.last %} class="active"{% endif %}>+ {% if not forloop.last %}+ <a href="{{ breadcrumb.get_absolute_url }}">{{ breadcrumb }}</a>+ {% else %}+ <span>{{ breadcrumb }}</span>+ {% endif %}+ </li>+ {% endfor %}{% endblock breadcrumb %}{% block content %}- <h2>{{ category }}</h2>- {% for row in products|slice:2 %}- <div class="row">- {% for product in row %}- <div class="col-sm-6">- <a href="{{ product.get_absolute_url }}">- {% if product.images.first %}- <img class="img-responsive" src="{{ product.images.first.image.thumbnail.750x750 }}" alt="">- {% else %}- <img src="{% static 'images/product-image-placeholder.png' %}" alt="" class="img-responsive">- {% endif %}- </a>- <h3><a href="{{ product.get_absolute_url }}">{{ product }}</a></h3>- {% 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 %}- <h4>- {% price_range price_range %}- {% if undiscounted.min_price != price_range.min_price %}- <span class="label label-success">{% trans "Discount!" %}</span>- {% endif %}- </h4>- {% endwith %}- {% endwith %}- {% endif %}- </div>- {% endfor %}+ <div class="row">+ <div class="col-md-3">+ <ul class="list-group">+ <li class="list-group-item active">+ {{ category }}+ </li>++ {% for category in children_categories %}+ <li class="list-group-item">+ <a href="{{ category.get_absolute_url }}">+ {{ category }}+ </a>+ </li>+ {% endfor %}+ </ul></div>- {% endfor %}++ <div class="col-md-9">+ <div class="row">+ {% include "category/_items.html" %}+ </div>+ </div>+ </div>{% endblock content %}diff --git a/saleor/product/views.py b/saleor/product/views.pyindex 2abd3eef51..eab0f8d0c7 100644--- a/saleor/product/views.py+++ b/saleor/product/views.py@@ -39,6 +39,8 @@ def product_details(request, slug, product_id):def category_index(request, path, category_id):category = get_object_or_404(Category, id=category_id)+ children_categories = category.get_children()+ breadcrumbs = category.get_ancestors(include_self=True)actual_path = category.get_full_path()if actual_path != path:return redirect('product:category', permanent=True, path=actual_path,@@ -47,4 +49,5 @@ def category_index(request, path, category_id):products = products.prefetch_related('images')return TemplateResponse(request, 'category/index.html',- {'products': products, 'category': category})+ {'products': products, 'category': category,+ 'children_categories': children_categories, 'breadcrumbs': breadcrumbs})diff --git a/saleor/static/scss/_app.scss b/saleor/static/scss/_app.scssindex 9b7e5bfff5..2c67ff110a 100644--- a/saleor/static/scss/_app.scss+++ b/saleor/static/scss/_app.scss@@ -21,6 +21,14 @@ $icon-font-path: "../fonts/";min-width: 200px;}+.product-list-item-name {+ display: block;+ margin-top: $grid-gutter-width/4;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+}+.product-gallery {margin-top: $grid-gutter-width;}diff --git a/templates/base.html b/templates/base.htmlindex f01ded954b..9122374f6c 100644--- a/templates/base.html+++ b/templates/base.html@@ -1,7 +1,5 @@<!DOCTYPE html>{% load i18n %}-{% load discounted_price_range price_difference from discount %}-{% load price_range from price_ranges %}{% load staticfiles %}<html lang="en">@@ -115,37 +113,7 @@<div class="col-sm-12">{% block content %}<div class="row">- {% for product in products %}- <div class="col-xs-12 col-sm-6 col-md-4 col-lg-3" itemscope itemtype="https://schema.org/Product">- <div class="panel panel-default text-center">- <div class="panel-body">- <a itemprop="url" href="{{ product.get_absolute_url }}">- {% if product.images.first %}- <img itemprop="image" class="img-responsive" src="{{ product.images.first.image.crop.400x400 }}" alt="">- {% else %}- <img src="{% static 'images/product-image-placeholder.png' %}" alt="" class="img-responsive">- {% endif %}- <span itemprop="name">{{ product }}</span>- </a>- </div>-- <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 %}- {% else %}- - {% endif %}- </div>- </div>- </div>- {% endfor %}+ {% include "category/_items.html" %}</div>{% endblock content %}</div>