Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix urls categories in homepage
Marcin Gębala6ae1faad36d3
diff --git a/saleor/core/views.py b/saleor/core/views.pyindex ea94641095..64f85bdf29 100644--- a/saleor/core/views.py+++ b/saleor/core/views.py@@ -1,12 +1,15 @@from django.template.response import TemplateResponse-from ..product.utils import products_with_availability, products_for_homepage+from ..product.utils import (categories_for_homepage,+ products_with_availability, products_for_homepage)def home(request):products = products_for_homepage()[:8]products = products_with_availability(products, discounts=request.discounts, local_currency=request.currency)+ featured_categories = categories_for_homepage(3)return TemplateResponse(request, 'home.html',- {'products': products, 'parent': None})+ {'products': products, 'parent': None,+ 'featured_categories': featured_categories})diff --git a/saleor/product/utils.py b/saleor/product/utils.pyindex cf128249fe..cf11eec837 100644--- a/saleor/product/utils.py+++ b/saleor/product/utils.py@@ -7,7 +7,7 @@ from ..cart.utils import get_cart_from_request, get_or_create_cart_from_requestfrom ..core.utils import to_local_currencyfrom .forms import get_form_class_for_productfrom .models.utils import get_attributes_display_map-from .models import Product+from .models import Category, Productdef products_visible_to_user(user):@@ -36,6 +36,13 @@ def products_for_homepage():return products+def categories_for_homepage(num):+ categories = list(Category.objects.all()[:num])+ while 0 < len(categories) < num:+ categories.append(Category.objects.first())+ return categories++def get_product_images(product):"""Returns list of product images that will be placed in product gallerydiff --git a/templates/home.html b/templates/home.htmlindex 987130eb26..61154bf6cf 100644--- a/templates/home.html+++ b/templates/home.html@@ -12,7 +12,7 @@<div class="home--content-inner"><h1>{% trans "Promo & Sale" %}</h1><h2>{% trans "form the Northpole" %}</h2>- <a class="btn btn-secondary home__button" href="/products/category/default-1/">{% trans "Shop now" %}</a>+ <a class="btn btn-secondary home__button" href="{% if featured_categories %}{{ featured_categories.0.get_absolute_url }}{% endif %}">{% trans "Shop now" %}</a></div></div></div>@@ -26,7 +26,7 @@<div class="home--content-wrapper"><div class="home--content-inner"><h1>{% trans "Size & Colours" %}</h1>- <a class="btn btn-secondary home__button" href="/products/category/groceries-2/">{% trans "Shop now" %}</a>+ <a class="btn btn-secondary home__button" href="{% if featured_categories %}{{ featured_categories.1.get_absolute_url }}{% endif %}">{% trans "Shop now" %}</a></div></div></div>@@ -38,7 +38,7 @@<div class="home--content-wrapper"><div class="home--content-inner"><h1>{% trans "Digital Downloads" %}</h1>- <a class="btn btn-secondary home__button" href="/products/category/accessories-3/">{% trans "Shop now" %}</a>+ <a class="btn btn-secondary home__button" href="{% if featured_categories %}{{ featured_categories.2.get_absolute_url }}{% endif %}">{% trans "Shop now" %}</a></div></div></div>