Add Redis-based persistence for POS cart and customer selection

Implemented Redis caching with 2-hour TTL for POS session data:

Backend changes:
- Added Redis cache configuration in settings.py
- Created save_cart() endpoint to persist cart state
- Added cart and customer loading from Redis in pos_terminal()
- Validates cart items (products/kits) still exist in DB
- Added REDIS_HOST, REDIS_PORT, REDIS_DB to .env

Frontend changes:
- Added saveCartToRedis() with 500ms debounce
- Cart auto-saves on add/remove/quantity change
- Added cart initialization from Redis on page load
- Enhanced customer button with two-line display and reset button
- Red X button appears only for non-system customers

Features:
- Cart persists across page reloads (2 hour TTL)
- Customer selection persists (2 hour TTL)
- Independent cart per user+warehouse combination
- Automatic cleanup of deleted items
- Debounced saves to reduce server load

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-20 09:55:03 +03:00
parent 685c06d94d
commit eac778b06d
5 changed files with 614 additions and 19 deletions

View File

@@ -9,6 +9,10 @@ urlpatterns = [
path('', views.pos_terminal, name='terminal'),
# Установить текущий склад для POS (сохранение в сессии) [POST]
path('api/set-warehouse/<int:warehouse_id>/', views.set_warehouse, name='set-warehouse'),
# Установить текущего клиента для POS (сохранение в Redis с TTL 2 часа) [POST]
path('api/set-customer/<int:customer_id>/', views.set_customer, name='set-customer'),
# Сохранить корзину POS (сохранение в Redis с TTL 2 часа) [POST]
path('api/save-cart/', views.save_cart, name='save-cart'),
# Получить товары и комплекты (пагинация, поиск, сортировка) [GET]
path('api/items/', views.get_items_api, name='items-api'),
# Получить список активных витрин [GET]