Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Handle collections with less than 6 products
Mira Szewczyk00f93cbe3bae
diff --git a/saleor/product/views.py b/saleor/product/views.pyindex a0bfb04c38..65b76eb11b 100644--- a/saleor/product/views.py+++ b/saleor/product/views.py@@ -1,6 +1,6 @@import datetimeimport json-from random import randint, shuffle+from random import randintfrom django.conf import settingsfrom django.http import HttpResponsePermanentRedirect, JsonResponse@@ -148,7 +148,10 @@ def products_from_collections(request, product_id):collections__products__id=product_id).exclude(id=product_id).distinct()products_count = products.count()- index = randint(0, products_count - 6)+ if products_count > 6:+ index = randint(0, products_count - 6)+ else:+ index = 0ctx = {'products': products[index:index + 6]}return TemplateResponse(request, 'product/_product_collections.html', ctx)