Files
apuc 37d5d7b366 Add the customer storefront on Django templates
Pages are rendered server-side (SEO, no build step), the interactive
parts talk to the existing REST API from the browser:

- home: banners, categories, hits and new arrivals
- catalog: filters (category, brand, price, stock), search, sorting,
  pagination, filter chips with one-click removal
- product card: gallery, price with discount, stock, characteristics,
  related products
- cart: localStorage, quantity controls, live totals
- checkout: contacts, delivery, promo code, bonuses, order submission
  with Idempotency-Key, success screen
- login: OTP by phone (debug code shown in dev) and phone/password
- account: profile, orders, addresses, bonuses through the API with JWT
- static pages from the admin

Supporting pieces:
- apps/storefront app with views, urls, templates and static CSS/JS
- money/discount/attribute template filters
- seed_demo management command with demo catalog, banners and pages
- Cyrillic search fallback for SQLite: local DB does not fold case for
  non-ASCII, production PostgreSQL does

Tests: 16 storefront cases (pages, filters, search, ordering, 404s,
filters formatting); the suite is 61 passing.
2026-11-22 22:38:39 +03:00

137 lines
5.5 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{% extends "storefront/base.html" %}
{% load storefront %}
{% block title %}{% if selected_category %}{{ selected_category.name }}{% else %}Каталог{% endif %} — {{ site.site_name }}{% endblock %}
{% block content %}
<div class="breadcrumbs">
<a href="{% url 'home' %}">Главная</a> /
{% if selected_category %}
<a href="{% url 'catalog' %}">Каталог</a> / <span>{{ selected_category.name }}</span>
{% else %}
<span>Каталог</span>
{% endif %}
</div>
<div class="page-head">
<h1>{% if selected_category %}{{ selected_category.name }}{% elif filters.search %}Поиск: {{ filters.search }}{% else %}Каталог{% endif %}</h1>
{% if selected_category.description %}<p>{{ selected_category.description }}</p>{% endif %}
</div>
<div class="catalog-layout">
<aside class="filters">
<form method="get" action="{% url 'catalog' %}">
<div class="filter-group">
<h4>Категория</h4>
<select name="category">
<option value="">Все категории</option>
{% for category in categories %}
<option value="{{ category.slug }}"
{% if filters.category == category.slug %}selected{% endif %}>{{ category.name }}</option>
{% endfor %}
</select>
</div>
<div class="filter-group">
<h4>Цена, ₽</h4>
<div class="filter-price">
<input type="number" name="price_min" min="0" inputmode="numeric"
placeholder="{{ price_bounds.low|money|default:'0' }}"
value="{{ filters.price_min|default:'' }}">
<input type="number" name="price_max" min="0" inputmode="numeric"
placeholder="{{ price_bounds.high|money|default:'—' }}"
value="{{ filters.price_max|default:'' }}">
</div>
</div>
{% if brands %}
<div class="filter-group">
<h4>Бренд</h4>
<select name="brand">
<option value="">Любой бренд</option>
{% for brand in brands %}
<option value="{{ brand }}" {% if filters.brand == brand %}selected{% endif %}>{{ brand }}</option>
{% endfor %}
</select>
</div>
{% endif %}
<div class="filter-group">
<label class="form-note">
<input type="checkbox" name="in_stock" value="1"
{% if filters.in_stock == '1' %}checked{% endif %}>
Только в наличии
</label>
</div>
{% if filters.search %}<input type="hidden" name="search" value="{{ filters.search }}">{% endif %}
<input type="hidden" name="ordering" value="{{ selected_ordering }}">
<div class="filter-actions">
<button class="btn btn-block" type="submit">Применить</button>
<a class="btn btn-outline btn-block" href="{% url 'catalog' %}">Сбросить</a>
</div>
</form>
</aside>
<div>
<div class="catalog-toolbar">
<span class="count">{% if total %}Найдено товаров: {{ total }}{% else %}Ничего не найдено{% endif %}</span>
<form method="get" action="{% url 'catalog' %}">
{% for key, value in filters.items %}
{% if key != 'ordering' %}<input type="hidden" name="{{ key }}" value="{{ value }}">{% endif %}
{% endfor %}
<select name="ordering" onchange="this.form.submit()" aria-label="Сортировка">
{% for value, label in ordering_choices %}
<option value="{{ value }}" {% if selected_ordering == value %}selected{% endif %}>{{ label }}</option>
{% endfor %}
</select>
</form>
</div>
{% if chips %}
<div class="chips">
{% for chip in chips %}
<span class="chip">
{{ chip.label }}{% if chip.value %}: {{ chip.value }}{% endif %}
<a href="{% url 'catalog' %}{% if chip.qs %}?{{ chip.qs }}{% endif %}" aria-label="Убрать фильтр">×</a>
</span>
{% endfor %}
</div>
{% endif %}
{% if products %}
<div class="product-grid">
{% for product in products %}
{% include "storefront/_product_card.html" %}
{% endfor %}
</div>
{% if page.paginator.num_pages > 1 %}
<nav class="pagination" aria-label="Страницы">
{% if page.has_previous %}
<a href="?{{ querystring }}&page={{ page.previous_page_number }}">←</a>
{% endif %}
{% for number in page.paginator.page_range %}
{% if number == page.number %}
<span class="current">{{ number }}</span>
{% elif number > page.number|add:"-3" and number < page.number|add:"3" %}
<a href="?{{ querystring }}&page={{ number }}">{{ number }}</a>
{% endif %}
{% endfor %}
{% if page.has_next %}
<a href="?{{ querystring }}&page={{ page.next_page_number }}">→</a>
{% endif %}
</nav>
{% endif %}
{% else %}
<div class="empty-state">
<h2>Товары не найдены</h2>
<p>Попробуйте изменить фильтры или сбросить их.</p>
<a class="btn btn-outline" href="{% url 'catalog' %}">Сбросить фильтры</a>
</div>
{% endif %}
</div>
</div>
{% endblock %}