Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Adapt search results page
Artur Smętffebe3a2b1a5
diff --git a/saleor/search/views.py b/saleor/search/views.pyindex aca02a1ff3..df8302e7b2 100644--- a/saleor/search/views.py+++ b/saleor/search/views.py@@ -5,7 +5,7 @@ from django.conf import settingsfrom django.http import Http404from django.shortcuts import renderfrom .forms import SearchForm-from ..product.utils import products_with_details+from ..product.utils import products_with_details, products_with_availabilitydef paginate_results(results, get_data, paginate_by=25):@@ -23,6 +23,10 @@ def search(request):if form.is_valid():visible_products = products_with_details(request.user)results = form.search(model_or_queryset=visible_products)+ results = products_with_availability(+ results, discounts=request.discounts,+ local_currency=request.currency)+ results = list(results)page = paginate_results(results, request.GET, settings.PAGINATE_BY)else:page = form.no_query_found()diff --git a/templates/base.html b/templates/base.htmlindex 79f7da08c9..49fc13313e 100644--- a/templates/base.html+++ b/templates/base.html@@ -62,10 +62,12 @@</div></div></div>- <form class="form-inline float-xs-right navbar__brand__search hidden-sm-down">- <input class="form-control" type="text" placeholder="Search">+ {% if SEARCH_IS_ENABLED %}+ <form class="form-inline float-xs-right navbar__brand__search hidden-sm-down" action="{% url "search:search" %}">+ <input class="form-control" type="text" placeholder="Search" name="q" value="{% if query %}{{ query }}{% endif %}"><button class="btn btn-link" type="submit"><img src="{% static "img/search-icon.svg" %}"></button></form>+ {% endif %}</div></div><div class="navbar__menu">diff --git a/templates/search/_items.html b/templates/search/_items.htmldeleted file mode 100644index 77bd1d9e23..0000000000--- a/templates/search/_items.html+++ /dev/null@@ -1,36 +0,0 @@-{% load i18n %}-{% load staticfiles %}-{% load price_range from price_ranges %}-{% load discounted_price_range price_difference from discount %}--{% for product in results %}- <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/templates/search/results.html b/templates/search/results.htmlindex 807fccee87..55ed2e6717 100644--- a/templates/search/results.html+++ b/templates/search/results.html@@ -20,16 +20,18 @@{% endblock breadcrumb %}{% block content %}- <div class="row">- {% if query and results %}- {% include "search/_items.html" %}- <div class="col-md-12">+ <div class="row home__featured">+ <div class="col-sm-12">+ {% if query and results %}+ <div class="row">+ {% include "category/_items.html" with products=results %}+ </div>{% bootstrap_pagination results url=query_string %}- </div>- {% else %}- <div class="col-md-12">- <h3>{% blocktrans %}No results found{% endblocktrans %}</h3>- </div>- {% endif %}+ {% else %}+ <div class="row">+ <h3>{% trans "No results" %}</h3>+ </div>+ {% endif %}+ </div></div>{% endblock content %}diff --git a/templates/search/search_form.html b/templates/search/search_form.htmldeleted file mode 100644index 439c3d5039..0000000000--- a/templates/search/search_form.html+++ /dev/null@@ -1,12 +0,0 @@-{% if SEARCH_IS_ENABLED %}-<form action="{% url "search:search" %}" method="get" class="navbar-form navbar-right">- <div class="input-group">- <input type="text" class="form-control" name="q" placeholder="Search..." value="{% if query %}{{ query }}{% endif %}" autofocus>- <span class="input-group-btn">- <button class="btn btn-default">- <span class="glyphicon glyphicon-search" aria-hidden="true"></span>- </button>- </span>- </div>-</form>-{% endif %}