Skip to content

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

Add featured products to the home page

weronka2f26629a47dd
diff --git a/saleor/core/views.py b/saleor/core/views.py
index b6f9aff3e8..e69ed47e89 100644
--- a/saleor/core/views.py
+++ b/saleor/core/views.py
@@ -4,9 +4,9 @@ from ..product.utils import products_with_availability, products_with_details
def home(request):
- products = products_with_details(request.user)[:12]
- products = products_with_availability(
- products, discounts=request.discounts, local_currency=request.currency)
+ products = Product.objects.get_available_products()[:6]
+ products = products.prefetch_related('categories', 'images',
+ 'variants__stock')
return TemplateResponse(
request, 'home.html',
{'products': products, 'parent': None})
diff --git a/templates/demo/category/_items.html b/templates/demo/category/_items.html
new file mode 100644
index 0000000000..aca7abdb1f
--- /dev/null
+++ b/templates/demo/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-6 col-md-4 product-list" itemscope itemtype="https://schema.org/Product" >
+ <div class="text-center">
+ <div>
+ <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__name" itemprop="name" title="{{ product }}">{{ product }}<br>-</span>
+ </a>
+ </div>
+
+ <div>
+ {% 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 %}
+ &nbsp;
+ {% endif %}
+ </div>
+ </div>
+ </div>
+{% endfor %}