Исправление багов авторизации, корзины и админки
- Исправлено выпадающее меню профиля (hover-баг с margin-top) - Исправлена авторизация: правильные пути к API (api/auth.php) - Исправлены ссылки на админку (admin/index.php вместо admin_panel.php) - Исправлены пути API корзины в catalog.php и checkout.php - Добавлена форма добавления/редактирования товаров в админке - Исправлены кнопки +/- в корзине (улучшена обработка AJAX) - Исправлена регистрация: правильные пути и обработка boolean в PostgreSQL - Добавлена миграция для назначения прав админа пользователю admin@mail.ru - Удален тестовый блок 'Быстрый вход' для неавторизованных пользователей - Улучшена обработка ошибок во всех API-эндпоинтах
This commit is contained in:
148
includes/auth.php
Normal file
148
includes/auth.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/**
|
||||
* Функции авторизации для AETERNA
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../config/database.php';
|
||||
|
||||
/**
|
||||
* Авторизация пользователя
|
||||
*/
|
||||
function loginUser(string $email, string $password): array {
|
||||
$db = Database::getInstance()->getConnection();
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare("
|
||||
SELECT user_id, email, password_hash, full_name, phone, city, is_admin, is_active
|
||||
FROM users WHERE email = ?
|
||||
");
|
||||
$stmt->execute([$email]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if (!$user) {
|
||||
return ['success' => false, 'message' => 'Пользователь не найден'];
|
||||
}
|
||||
|
||||
if (!$user['is_active']) {
|
||||
return ['success' => false, 'message' => 'Аккаунт заблокирован'];
|
||||
}
|
||||
|
||||
if (!password_verify($password, $user['password_hash'])) {
|
||||
return ['success' => false, 'message' => 'Неверный пароль'];
|
||||
}
|
||||
|
||||
// Сохраняем в сессию
|
||||
$_SESSION['user_id'] = $user['user_id'];
|
||||
$_SESSION['user_email'] = $user['email'];
|
||||
$_SESSION['full_name'] = $user['full_name'];
|
||||
$_SESSION['user_phone'] = $user['phone'] ?? '';
|
||||
$_SESSION['user_city'] = $user['city'] ?? '';
|
||||
$_SESSION['isLoggedIn'] = true;
|
||||
$_SESSION['isAdmin'] = (bool)$user['is_admin'];
|
||||
$_SESSION['login_time'] = time();
|
||||
|
||||
// Обновляем время последнего входа
|
||||
$updateStmt = $db->prepare("UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE user_id = ?");
|
||||
$updateStmt->execute([$user['user_id']]);
|
||||
|
||||
return ['success' => true, 'user' => $user];
|
||||
|
||||
} catch (PDOException $e) {
|
||||
return ['success' => false, 'message' => 'Ошибка базы данных'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Регистрация нового пользователя
|
||||
*/
|
||||
function registerUser(array $data): array {
|
||||
$db = Database::getInstance()->getConnection();
|
||||
|
||||
$email = trim($data['email'] ?? '');
|
||||
$password = $data['password'] ?? '';
|
||||
$fullName = trim($data['full_name'] ?? '');
|
||||
$phone = trim($data['phone'] ?? '');
|
||||
$city = trim($data['city'] ?? '');
|
||||
|
||||
// Валидация
|
||||
if (empty($email) || empty($password) || empty($fullName)) {
|
||||
return ['success' => false, 'message' => 'Заполните все обязательные поля'];
|
||||
}
|
||||
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
return ['success' => false, 'message' => 'Некорректный email'];
|
||||
}
|
||||
|
||||
if (strlen($password) < 6) {
|
||||
return ['success' => false, 'message' => 'Пароль должен содержать минимум 6 символов'];
|
||||
}
|
||||
|
||||
try {
|
||||
// Проверяем существование пользователя
|
||||
$checkStmt = $db->prepare("SELECT user_id FROM users WHERE email = ?");
|
||||
$checkStmt->execute([$email]);
|
||||
|
||||
if ($checkStmt->fetch()) {
|
||||
return ['success' => false, 'message' => 'Пользователь с таким email уже существует'];
|
||||
}
|
||||
|
||||
// Создаем пользователя
|
||||
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
|
||||
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO users (email, password_hash, full_name, phone, city, is_active)
|
||||
VALUES (?, ?, ?, ?, ?, TRUE)
|
||||
RETURNING user_id
|
||||
");
|
||||
$stmt->execute([$email, $passwordHash, $fullName, $phone, $city]);
|
||||
$userId = $stmt->fetchColumn();
|
||||
|
||||
// Автоматически авторизуем
|
||||
$_SESSION['user_id'] = $userId;
|
||||
$_SESSION['user_email'] = $email;
|
||||
$_SESSION['full_name'] = $fullName;
|
||||
$_SESSION['user_phone'] = $phone;
|
||||
$_SESSION['user_city'] = $city;
|
||||
$_SESSION['isLoggedIn'] = true;
|
||||
$_SESSION['isAdmin'] = false;
|
||||
$_SESSION['login_time'] = time();
|
||||
|
||||
return ['success' => true, 'user_id' => $userId];
|
||||
|
||||
} catch (PDOException $e) {
|
||||
return ['success' => false, 'message' => 'Ошибка базы данных: ' . $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Выход пользователя
|
||||
*/
|
||||
function logoutUser(): void {
|
||||
$_SESSION = [];
|
||||
|
||||
if (ini_get("session.use_cookies")) {
|
||||
$params = session_get_cookie_params();
|
||||
setcookie(session_name(), '', time() - 42000,
|
||||
$params["path"], $params["domain"],
|
||||
$params["secure"], $params["httponly"]
|
||||
);
|
||||
}
|
||||
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка является ли пользователь администратором
|
||||
*/
|
||||
function checkAdminAccess(): bool {
|
||||
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($_SESSION['isAdmin']) || $_SESSION['isAdmin'] !== true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
50
includes/footer.php
Normal file
50
includes/footer.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<footer class="footer" id="footer">
|
||||
<div class="container footer__content">
|
||||
<div class="footer__col footer--logo">
|
||||
<div class="logo">AETERNA</div>
|
||||
</div>
|
||||
|
||||
<div class="footer__col">
|
||||
<h5>ПОКУПАТЕЛЮ</h5>
|
||||
<ul>
|
||||
<li><a href="catalog.php">Каталог</a></li>
|
||||
<li><a href="services.php">Услуги</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="footer__col">
|
||||
<h5>ПОМОЩЬ</h5>
|
||||
<ul>
|
||||
<li><a href="delivery.php">Доставка и оплата</a></li>
|
||||
<li><a href="warranty.php">Гарантия и возврат</a></li>
|
||||
<li><a href="index.php#faq">Ответы на вопросы</a></li>
|
||||
<li><a href="#footer">Контакты</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="footer__col">
|
||||
<h5>КОНТАКТЫ</h5>
|
||||
<p>aeterna@mail.ru</p>
|
||||
<p>+7(912)999-12-23</p>
|
||||
<div class="social-icons">
|
||||
<span class="icon"><i class="fab fa-telegram"></i></span>
|
||||
<span class="icon"><i class="fab fa-instagram"></i></span>
|
||||
<span class="icon"><i class="fab fa-vk"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer__col">
|
||||
<h5>ПРИНИМАЕМ К ОПЛАТЕ</h5>
|
||||
<div class="payment-icons">
|
||||
<span class="pay-icon"><i class="fab fa-cc-visa"></i></span>
|
||||
<span class="pay-icon"><i class="fab fa-cc-mastercard"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="copyright">
|
||||
<p>© 2025 AETERNA. Все права защищены.</p>
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
140
includes/functions.php
Normal file
140
includes/functions.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
* Общие функции для AETERNA
|
||||
*/
|
||||
|
||||
/**
|
||||
* Проверка авторизации пользователя
|
||||
*/
|
||||
function isLoggedIn(): bool {
|
||||
return isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка прав администратора
|
||||
*/
|
||||
function isAdmin(): bool {
|
||||
return isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Требовать авторизацию - редирект на login если не авторизован
|
||||
*/
|
||||
function requireAuth(string $redirectUrl = 'login.php'): void {
|
||||
if (!isLoggedIn()) {
|
||||
header('Location: ' . $redirectUrl . '?error=auth_required&redirect=' . urlencode($_SERVER['REQUEST_URI']));
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Требовать права администратора
|
||||
*/
|
||||
function requireAdmin(string $redirectUrl = 'login.php'): void {
|
||||
if (!isAdmin()) {
|
||||
header('Location: ' . $redirectUrl . '?error=admin_required');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить текущего пользователя
|
||||
*/
|
||||
function getCurrentUser(): ?array {
|
||||
if (!isLoggedIn()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'user_id' => $_SESSION['user_id'] ?? 0,
|
||||
'email' => $_SESSION['user_email'] ?? '',
|
||||
'full_name' => $_SESSION['full_name'] ?? '',
|
||||
'is_admin' => isAdmin()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Форматирование цены
|
||||
*/
|
||||
function formatPrice(float $price): string {
|
||||
return number_format($price, 0, '', ' ') . ' ₽';
|
||||
}
|
||||
|
||||
/**
|
||||
* Безопасный вывод HTML
|
||||
*/
|
||||
function e(string $str): string {
|
||||
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Генерация номера заказа
|
||||
*/
|
||||
function generateOrderNumber(): string {
|
||||
return 'AET-' . date('Ymd') . '-' . strtoupper(substr(uniqid(), -6));
|
||||
}
|
||||
|
||||
/**
|
||||
* Генерация SKU для товара
|
||||
*/
|
||||
function generateSKU(string $productName): string {
|
||||
$prefix = strtoupper(substr(preg_replace('/[^a-zA-Z0-9]/', '', transliterate($productName)), 0, 6));
|
||||
return $prefix . '-' . rand(100, 999);
|
||||
}
|
||||
|
||||
/**
|
||||
* Транслитерация кириллицы в латиницу
|
||||
*/
|
||||
function transliterate(string $str): string {
|
||||
$converter = [
|
||||
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd',
|
||||
'е' => 'e', 'ё' => 'e', 'ж' => 'zh', 'з' => 'z', 'и' => 'i',
|
||||
'й' => 'y', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n',
|
||||
'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't',
|
||||
'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c', 'ч' => 'ch',
|
||||
'ш' => 'sh', 'щ' => 'sch', 'ь' => '', 'ы' => 'y', 'ъ' => '',
|
||||
'э' => 'e', 'ю' => 'yu', 'я' => 'ya',
|
||||
'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D',
|
||||
'Е' => 'E', 'Ё' => 'E', 'Ж' => 'Zh', 'З' => 'Z', 'И' => 'I',
|
||||
'Й' => 'Y', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N',
|
||||
'О' => 'O', 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T',
|
||||
'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', 'Ч' => 'Ch',
|
||||
'Ш' => 'Sh', 'Щ' => 'Sch', 'Ь' => '', 'Ы' => 'Y', 'Ъ' => '',
|
||||
'Э' => 'E', 'Ю' => 'Yu', 'Я' => 'Ya',
|
||||
];
|
||||
return strtr($str, $converter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Создание slug из строки
|
||||
*/
|
||||
function createSlug(string $str): string {
|
||||
$slug = transliterate($str);
|
||||
$slug = strtolower($slug);
|
||||
$slug = preg_replace('/[^a-z0-9]+/', '-', $slug);
|
||||
$slug = trim($slug, '-');
|
||||
return $slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Показать flash-сообщение
|
||||
*/
|
||||
function setFlashMessage(string $type, string $message): void {
|
||||
$_SESSION['flash_message'] = [
|
||||
'type' => $type,
|
||||
'message' => $message
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить и удалить flash-сообщение
|
||||
*/
|
||||
function getFlashMessage(): ?array {
|
||||
if (isset($_SESSION['flash_message'])) {
|
||||
$message = $_SESSION['flash_message'];
|
||||
unset($_SESSION['flash_message']);
|
||||
return $message;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
181
includes/header.php
Normal file
181
includes/header.php
Normal file
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
/**
|
||||
* Единый header для всех страниц AETERNA
|
||||
* Подключение: require_once 'includes/header.php';
|
||||
*/
|
||||
|
||||
// Запускаем сессию если еще не запущена
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
// Определяем текущую страницу
|
||||
$currentPage = basename($_SERVER['PHP_SELF'], '.php');
|
||||
|
||||
// Проверяем авторизацию
|
||||
$isLoggedIn = isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] === true;
|
||||
$isAdmin = isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] === true;
|
||||
$userEmail = $_SESSION['user_email'] ?? '';
|
||||
$fullName = $_SESSION['full_name'] ?? $userEmail;
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>AETERNA - <?= $pageTitle ?? 'Мебель и Интерьер' ?></title>
|
||||
<link rel="stylesheet/less" type="text/css" href="assets/less/style.less">
|
||||
<script src="https://cdn.jsdelivr.net/npm/less"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
||||
<style>
|
||||
/* Стили для профиля пользователя */
|
||||
.user-profile-dropdown { position: relative; display: inline-block; }
|
||||
.user-profile-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 8px 12px; border-radius: 4px; transition: all 0.3s ease; }
|
||||
.user-profile-toggle:hover { background-color: rgba(0, 0, 0, 0.05); }
|
||||
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, #617365 0%, #453227 100%); color: white; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 16px; }
|
||||
.user-info { display: flex; flex-direction: column; }
|
||||
.user-email { font-size: 12px; color: #666; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.user-status { font-size: 10px; padding: 2px 8px; border-radius: 12px; text-transform: uppercase; font-weight: bold; text-align: center; margin-top: 2px; }
|
||||
.user-status.admin { background-color: #617365; color: white; }
|
||||
.user-status.user { background-color: #28a745; color: white; }
|
||||
.user-profile-menu { display: none; position: absolute; top: 100%; right: 0; background: white; min-width: 280px; border-radius: 8px; box-shadow: 0 5px 20px rgba(0,0,0,0.15); z-index: 1000; margin-top: 10px; border: 1px solid #e0e0e0; overflow: hidden; }
|
||||
.user-profile-header { padding: 15px; background: #f8f9fa; border-bottom: 1px solid #e0e0e0; }
|
||||
.user-profile-name { font-weight: bold; margin-bottom: 5px; color: #333; display: flex; align-items: center; gap: 8px; }
|
||||
.user-profile-links { list-style: none; padding: 10px 0; margin: 0; }
|
||||
.user-profile-links a { display: flex; align-items: center; gap: 10px; padding: 10px 15px; color: #333; text-decoration: none; transition: all 0.3s ease; border-left: 3px solid transparent; }
|
||||
.user-profile-links a:hover { background-color: #f5f5f5; border-left-color: #453227; color: #453227; }
|
||||
.logout-link { color: #dc3545 !important; }
|
||||
.logout-link:hover { background-color: #ffe6e6 !important; border-left-color: #dc3545 !important; }
|
||||
.cart-icon { position: relative; margin-right: 15px; }
|
||||
.cart-count { position: absolute; top: -8px; right: -8px; background: #dc3545; color: white; border-radius: 50%; width: 18px; height: 18px; font-size: 11px; display: flex; align-items: center; justify-content: center; }
|
||||
</style>
|
||||
<?php if (isset($additionalStyles)): ?>
|
||||
<style><?= $additionalStyles ?></style>
|
||||
<?php endif; ?>
|
||||
</head>
|
||||
<body>
|
||||
<header class="header">
|
||||
<div class="header__top">
|
||||
<div class="container header__top-content">
|
||||
<div class="logo"><a href="index.php" style="text-decoration: none; color: inherit;">AETERNA</a></div>
|
||||
|
||||
<div class="search-catalog">
|
||||
<div class="catalog-dropdown">
|
||||
Все категории <span>▼</span>
|
||||
<div class="catalog-dropdown__menu">
|
||||
<ul>
|
||||
<li><a href="catalog.php">Все товары</a></li>
|
||||
<li><a href="catalog.php?category=1">Диваны</a></li>
|
||||
<li><a href="catalog.php?category=2">Кресла</a></li>
|
||||
<li><a href="catalog.php?category=3">Кровати</a></li>
|
||||
<li><a href="catalog.php?category=4">Столы</a></li>
|
||||
<li><a href="catalog.php?category=5">Стулья</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="search-box">
|
||||
<form method="GET" action="catalog.php" style="display: flex; width: 100%;">
|
||||
<input type="text" name="search" placeholder="Поиск товаров" style="border: none; width: 100%; padding: 10px;">
|
||||
<button type="submit" style="background: none; border: none; cursor: pointer;">
|
||||
<span class="search-icon"><i class="fas fa-search"></i></span>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="header__icons--top">
|
||||
<?php if ($isLoggedIn): ?>
|
||||
<!-- Иконка корзины -->
|
||||
<a href="checkout.php" class="icon cart-icon">
|
||||
<i class="fas fa-shopping-cart"></i>
|
||||
<span class="cart-count" id="cartCount">0</span>
|
||||
</a>
|
||||
|
||||
<!-- Блок профиля -->
|
||||
<div class="user-profile-dropdown">
|
||||
<div class="user-profile-toggle" id="profileToggle">
|
||||
<div class="user-avatar"><?= !empty($userEmail) ? strtoupper(substr($userEmail, 0, 1)) : 'U' ?></div>
|
||||
<div class="user-info">
|
||||
<div class="user-email"><?= htmlspecialchars($userEmail) ?></div>
|
||||
<div class="user-status <?= $isAdmin ? 'admin' : 'user' ?>"><?= $isAdmin ? 'Админ' : 'Пользователь' ?></div>
|
||||
</div>
|
||||
<i class="fas fa-chevron-down" style="font-size: 12px; color: #666;"></i>
|
||||
</div>
|
||||
|
||||
<div class="user-profile-menu" id="profileMenu">
|
||||
<div class="user-profile-header">
|
||||
<div class="user-profile-name"><i class="fas fa-user"></i> <?= htmlspecialchars($fullName) ?></div>
|
||||
</div>
|
||||
<ul class="user-profile-links">
|
||||
<li><a href="profile.php"><i class="fas fa-user-cog"></i> Мой профиль</a></li>
|
||||
<li><a href="checkout.php"><i class="fas fa-shopping-bag"></i> Мои заказы</a></li>
|
||||
<?php if ($isAdmin): ?>
|
||||
<li><a href="admin/index.php"><i class="fas fa-user-shield"></i> Админ-панель</a></li>
|
||||
<?php endif; ?>
|
||||
<li><a href="logout.php" class="logout-link"><i class="fas fa-sign-out-alt"></i> Выйти</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<a href="login.php" class="icon"><i class="far fa-user"></i></a>
|
||||
<a href="login.php" style="font-size: 12px; color: #666; margin-left: 5px;">Войти</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="header__bottom">
|
||||
<div class="container header__bottom-content">
|
||||
<div class="catalog-menu">
|
||||
<a href="catalog.php" class="catalog-link <?= $currentPage === 'catalog' ? 'active' : '' ?>">
|
||||
<span class="catalog-lines">☰</span> Каталог
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<nav class="nav">
|
||||
<ul class="nav-list">
|
||||
<li><a href="index.php" class="<?= $currentPage === 'index' || $currentPage === 'cite_mebel' ? 'active' : '' ?>">Главная</a></li>
|
||||
<li><a href="services.php" class="<?= $currentPage === 'services' ? 'active' : '' ?>">Услуги</a></li>
|
||||
<li><a href="delivery.php" class="<?= $currentPage === 'delivery' ? 'active' : '' ?>">Доставка и оплата</a></li>
|
||||
<li><a href="warranty.php" class="<?= $currentPage === 'warranty' ? 'active' : '' ?>">Гарантия</a></li>
|
||||
<li><a href="#footer">Контакты</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
<div class="header-phone">+7(912)999-12-23</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Профиль пользователя - открытие/закрытие
|
||||
$('#profileToggle').click(function(e) {
|
||||
e.stopPropagation();
|
||||
$('#profileMenu').toggle();
|
||||
});
|
||||
|
||||
$(document).click(function(e) {
|
||||
if (!$(e.target).closest('.user-profile-dropdown').length) {
|
||||
$('#profileMenu').hide();
|
||||
}
|
||||
});
|
||||
|
||||
// Обновление счетчика корзины
|
||||
<?php if ($isLoggedIn): ?>
|
||||
$.ajax({
|
||||
url: 'api/cart.php?action=count',
|
||||
method: 'GET',
|
||||
success: function(response) {
|
||||
try {
|
||||
const result = JSON.parse(response);
|
||||
if (result.success) {
|
||||
$('#cartCount').text(result.count);
|
||||
}
|
||||
} catch(e) {}
|
||||
}
|
||||
});
|
||||
<?php endif; ?>
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user