diff --git a/counter/templates/counter/counter_click.jinja b/counter/templates/counter/counter_click.jinja
index ed40e584..c97b1708 100644
--- a/counter/templates/counter/counter_click.jinja
+++ b/counter/templates/counter/counter_click.jinja
@@ -23,7 +23,7 @@
{% endblock %}
{% block content %}
-
- {% for t in categories -%}
- {%- if counter.products.filter(product_type=t).exists() -%}
- - {{ t }}
- {%- endif -%}
+ {% for category in categories.keys() -%}
+ - {{ category }}
{%- endfor %}
- {% for t in categories -%}
- {%- if counter.products.filter(product_type=t).exists() -%}
-
-
{{ t }}
- {% for p in counter.products.filter(product_type=t).all() -%}
+ {% for category in categories.keys() -%}
+
+
{{ category }}
+ {% for p in categories[category] -%}
{% set file = None %}
{% if p.icon %}
{% set file = p.icon.url %}
@@ -148,18 +145,20 @@
{{ add_product(p.id, prod, "form_button") }}
{%- endfor %}
- {%- endif -%}
{%- endfor %}
{% endblock %}
{% block script %}
+
{{ super() }}
{% endblock %}
-
-
-
diff --git a/counter/views.py b/counter/views.py
index c2e2d672..663b3008 100644
--- a/counter/views.py
+++ b/counter/views.py
@@ -708,10 +708,16 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView):
def get_context_data(self, **kwargs):
""" Add customer to the context """
kwargs = super(CounterClick, self).get_context_data(**kwargs)
+ kwargs["products"] = self.object.products.select_related("product_type")
+ kwargs["categories"] = {}
+ for product in kwargs["products"]:
+ if product.product_type:
+ kwargs["categories"].setdefault(product.product_type, []).append(
+ product
+ )
kwargs["customer"] = self.customer
kwargs["basket_total"] = self.sum_basket(self.request)
kwargs["refill_form"] = self.refill_form or RefillForm()
- kwargs["categories"] = ProductType.objects.all()
kwargs["student_card_max_uid_size"] = StudentCard.UID_SIZE
return kwargs