Feat: Add catalog page with category tree and product grid

- Create catalog view with recursive category tree building
- Add left-side category tree with expand/collapse functionality
- Add right-side product/kit grid with filtering and search
- Include category navigation with product/kit counts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-24 00:31:37 +03:00
parent 157bd50082
commit 4549b2c2c2
8 changed files with 382 additions and 9 deletions

View File

@@ -95,6 +95,9 @@ from .configurablekit_views import (
# API представления
from .api_views import search_products_and_variants, validate_kit_cost, create_temporary_kit_api, create_tag_api
# Каталог
from .catalog_views import CatalogView
__all__ = [
# Утилиты
@@ -174,4 +177,7 @@ __all__ = [
'validate_kit_cost',
'create_temporary_kit_api',
'create_tag_api',
# Каталог
'CatalogView',
]

View File

@@ -0,0 +1,52 @@
"""
Представление для каталога товаров и комплектов.
"""
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import TemplateView
from ..models import Product, ProductKit, ProductCategory
class CatalogView(LoginRequiredMixin, TemplateView):
"""Каталог с деревом категорий слева и сеткой товаров справа."""
template_name = 'products/catalog.html'
def build_category_tree(self, categories, parent=None):
"""Рекурсивно строит дерево категорий с товарами."""
tree = []
for cat in categories:
if cat.parent_id == (parent.pk if parent else None):
children = self.build_category_tree(categories, cat)
tree.append({
'category': cat,
'children': children,
})
return tree
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
# Все активные категории
categories = list(ProductCategory.objects.filter(
is_active=True, is_deleted=False
).prefetch_related('products', 'kits').order_by('name'))
# Строим дерево
category_tree = self.build_category_tree(categories, parent=None)
# Товары и комплекты для правой панели
products = Product.objects.filter(status='active').prefetch_related('photos').order_by('name')
for p in products:
p.item_type = 'product'
p.main_photo = p.photos.order_by('order').first()
kits = ProductKit.objects.filter(status='active', is_temporary=False).prefetch_related('photos').order_by('name')
for k in kits:
k.item_type = 'kit'
k.main_photo = k.photos.order_by('order').first()
items = sorted(list(products) + list(kits), key=lambda x: x.name)
context['category_tree'] = category_tree
context['items'] = items
return context