Fix
This commit is contained in:
@@ -282,6 +282,34 @@ try {
|
||||
}
|
||||
break;
|
||||
|
||||
case 'order_details':
|
||||
if (isset($_GET['id'])) {
|
||||
$orderId = (int)$_GET['id'];
|
||||
|
||||
// Получаем информацию о заказе
|
||||
$stmt = $db->prepare("
|
||||
SELECT o.*, u.email as user_email, u.full_name as user_full_name
|
||||
FROM orders o
|
||||
LEFT JOIN users u ON o.user_id = u.user_id
|
||||
WHERE o.order_id = ?
|
||||
");
|
||||
$stmt->execute([$orderId]);
|
||||
$order = $stmt->fetch();
|
||||
|
||||
// Получаем товары в заказе
|
||||
if ($order) {
|
||||
$stmt = $db->prepare("
|
||||
SELECT oi.*, p.image_url
|
||||
FROM order_items oi
|
||||
LEFT JOIN products p ON oi.product_id = p.product_id
|
||||
WHERE oi.order_id = ?
|
||||
");
|
||||
$stmt->execute([$orderId]);
|
||||
$order_items = $stmt->fetchAll();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
@@ -296,6 +324,7 @@ try {
|
||||
<base href="/cite_practica/admin/">
|
||||
<title>AETERNA - Админ-панель</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; margin: 0; padding: 0; background: #f5f5f5; }
|
||||
.admin-header { background: #453227; color: white; padding: 20px; display: flex; justify-content: space-between; align-items: center; }
|
||||
@@ -501,7 +530,7 @@ try {
|
||||
</a>
|
||||
<button type="button" class="btn btn-danger btn-sm delete-category-btn"
|
||||
data-id="<?= $category['category_id'] ?>"
|
||||
<?= $category['product_count'] > 0 ? 'disabled' : '' ?>>
|
||||
data-has-products="<?= $category['product_count'] > 0 ? '1' : '0' ?>">
|
||||
<i class="fas fa-trash"></i> Удалить
|
||||
</button>
|
||||
</td>
|
||||
@@ -739,47 +768,219 @@ try {
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php elseif ($action == 'order_details'): ?>
|
||||
|
||||
<?php if (isset($order) && $order): ?>
|
||||
<div style="margin-bottom: 20px;">
|
||||
<a href="index.php?action=orders" class="btn btn-primary">
|
||||
<i class="fas fa-arrow-left"></i> Назад к заказам
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<h2>Детали заказа #<?= htmlspecialchars($order['order_number']) ?></h2>
|
||||
|
||||
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;">
|
||||
<!-- Информация о заказе -->
|
||||
<div style="background: white; padding: 20px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);">
|
||||
<h3 style="margin-top: 0;">Информация о заказе</h3>
|
||||
<table style="width: 100%; border: none;">
|
||||
<tr>
|
||||
<td style="border: none; padding: 8px 0;"><strong>Номер заказа:</strong></td>
|
||||
<td style="border: none; padding: 8px 0;"><?= htmlspecialchars($order['order_number']) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border: none; padding: 8px 0;"><strong>Дата создания:</strong></td>
|
||||
<td style="border: none; padding: 8px 0;"><?= date('d.m.Y H:i', strtotime($order['created_at'])) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border: none; padding: 8px 0;"><strong>Статус:</strong></td>
|
||||
<td style="border: none; padding: 8px 0;">
|
||||
<span style="padding: 5px 10px; border-radius: 4px; background:
|
||||
<?php
|
||||
echo match($order['status']) {
|
||||
'pending' => '#ffc107',
|
||||
'processing' => '#17a2b8',
|
||||
'completed' => '#28a745',
|
||||
'cancelled' => '#dc3545',
|
||||
default => '#6c757d'
|
||||
};
|
||||
?>; color: white;">
|
||||
<?= htmlspecialchars($order['status']) ?>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border: none; padding: 8px 0;"><strong>Способ оплаты:</strong></td>
|
||||
<td style="border: none; padding: 8px 0;"><?= $order['payment_method'] == 'card' ? 'Банковская карта' : 'Наличные' ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border: none; padding: 8px 0;"><strong>Способ доставки:</strong></td>
|
||||
<td style="border: none; padding: 8px 0;"><?= $order['delivery_method'] == 'courier' ? 'Курьерская доставка' : 'Самовывоз' ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Информация о клиенте -->
|
||||
<div style="background: white; padding: 20px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);">
|
||||
<h3 style="margin-top: 0;">Информация о клиенте</h3>
|
||||
<table style="width: 100%; border: none;">
|
||||
<tr>
|
||||
<td style="border: none; padding: 8px 0;"><strong>ФИО:</strong></td>
|
||||
<td style="border: none; padding: 8px 0;"><?= htmlspecialchars($order['customer_name']) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border: none; padding: 8px 0;"><strong>Email:</strong></td>
|
||||
<td style="border: none; padding: 8px 0;"><?= htmlspecialchars($order['customer_email']) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border: none; padding: 8px 0;"><strong>Телефон:</strong></td>
|
||||
<td style="border: none; padding: 8px 0;"><?= htmlspecialchars($order['customer_phone']) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border: none; padding: 8px 0;"><strong>Регион:</strong></td>
|
||||
<td style="border: none; padding: 8px 0;"><?= htmlspecialchars($order['delivery_region'] ?? '—') ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border: none; padding: 8px 0;"><strong>Адрес доставки:</strong></td>
|
||||
<td style="border: none; padding: 8px 0;"><?= htmlspecialchars($order['delivery_address']) ?></td>
|
||||
</tr>
|
||||
<?php if (!empty($order['postal_code'])): ?>
|
||||
<tr>
|
||||
<td style="border: none; padding: 8px 0;"><strong>Индекс:</strong></td>
|
||||
<td style="border: none; padding: 8px 0;"><?= htmlspecialchars($order['postal_code']) ?></td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Товары в заказе -->
|
||||
<div style="background: white; padding: 20px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); margin-bottom: 20px;">
|
||||
<h3 style="margin-top: 0;">Товары в заказе</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Изображение</th>
|
||||
<th>Товар</th>
|
||||
<th>Цена</th>
|
||||
<th>Количество</th>
|
||||
<th>Сумма</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($order_items as $item): ?>
|
||||
<tr>
|
||||
<td>
|
||||
<?php if (!empty($item['image_url'])): ?>
|
||||
<img src="/cite_practica/<?= htmlspecialchars($item['image_url']) ?>"
|
||||
alt="<?= htmlspecialchars($item['product_name']) ?>"
|
||||
style="width: 60px; height: 60px; object-fit: cover; border-radius: 4px;">
|
||||
<?php else: ?>
|
||||
<div style="width: 60px; height: 60px; background: #f0f0f0; display: flex; align-items: center; justify-content: center; border-radius: 4px;">
|
||||
<i class="fas fa-image" style="color: #ccc;"></i>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?= htmlspecialchars($item['product_name']) ?></td>
|
||||
<td><?= number_format($item['product_price'], 0, '', ' ') ?> ₽</td>
|
||||
<td><?= $item['quantity'] ?> шт.</td>
|
||||
<td><?= number_format($item['total_price'], 0, '', ' ') ?> ₽</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Итоговая сумма -->
|
||||
<div style="background: white; padding: 20px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); max-width: 400px; margin-left: auto;">
|
||||
<h3 style="margin-top: 0;">Итого</h3>
|
||||
<table style="width: 100%; border: none;">
|
||||
<tr>
|
||||
<td style="border: none; padding: 8px 0;">Товары:</td>
|
||||
<td style="border: none; padding: 8px 0; text-align: right;"><?= number_format($order['subtotal'], 0, '', ' ') ?> ₽</td>
|
||||
</tr>
|
||||
<?php if ($order['discount_amount'] > 0): ?>
|
||||
<tr>
|
||||
<td style="border: none; padding: 8px 0;">Скидка:</td>
|
||||
<td style="border: none; padding: 8px 0; text-align: right; color: #28a745;">-<?= number_format($order['discount_amount'], 0, '', ' ') ?> ₽</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
<tr>
|
||||
<td style="border: none; padding: 8px 0;">Доставка:</td>
|
||||
<td style="border: none; padding: 8px 0; text-align: right;"><?= number_format($order['delivery_price'], 0, '', ' ') ?> ₽</td>
|
||||
</tr>
|
||||
<tr style="font-size: 18px; font-weight: bold;">
|
||||
<td style="border: none; padding: 12px 0; border-top: 2px solid #ddd;">Итого к оплате:</td>
|
||||
<td style="border: none; padding: 12px 0; text-align: right; border-top: 2px solid #ddd;"><?= number_format($order['final_amount'], 0, '', ' ') ?> ₽</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($order['notes'])): ?>
|
||||
<div style="background: white; padding: 20px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); margin-top: 20px;">
|
||||
<h3 style="margin-top: 0;">Примечания</h3>
|
||||
<p><?= htmlspecialchars($order['notes']) ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php else: ?>
|
||||
<div class="alert alert-danger">
|
||||
<i class="fas fa-exclamation-circle"></i> Заказ не найден
|
||||
</div>
|
||||
<a href="index.php?action=orders" class="btn btn-primary">Вернуться к списку заказов</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<script>
|
||||
$('.delete-category-btn').click(function() {
|
||||
const categoryId = $(this).data('id');
|
||||
const btn = $(this);
|
||||
$(document).ready(function() {
|
||||
$('.delete-category-btn').click(function() {
|
||||
const categoryId = $(this).data('id');
|
||||
const btn = $(this);
|
||||
|
||||
if (confirm('Удалить эту категорию?')) {
|
||||
$.ajax({
|
||||
url: 'fix_delete_category.php',
|
||||
method: 'POST',
|
||||
data: { category_id: categoryId },
|
||||
dataType: 'json',
|
||||
success: function(result) {
|
||||
if (result.success) {
|
||||
alert(result.message);
|
||||
location.reload();
|
||||
} else {
|
||||
alert('Ошибка: ' + result.message);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX error:', status, error);
|
||||
alert('Ошибка при удалении категории: ' + error);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('#categoryForm').submit(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (confirm('Удалить эту категорию?')) {
|
||||
$.ajax({
|
||||
url: 'fix_delete_category.php',
|
||||
url: $(this).attr('action'),
|
||||
method: 'POST',
|
||||
data: { category_id: categoryId },
|
||||
success: function(response) {
|
||||
const result = JSON.parse(response);
|
||||
data: $(this).serialize(),
|
||||
dataType: 'json',
|
||||
success: function(result) {
|
||||
if (result.success) {
|
||||
alert(result.message);
|
||||
location.reload();
|
||||
window.location.href = 'index.php?action=categories';
|
||||
} else {
|
||||
alert('Ошибка: ' + result.message);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX error:', status, error);
|
||||
alert('Ошибка при сохранении категории');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('#categoryForm').submit(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$.ajax({
|
||||
url: $(this).attr('action'),
|
||||
method: 'POST',
|
||||
data: $(this).serialize(),
|
||||
success: function(response) {
|
||||
const result = JSON.parse(response);
|
||||
if (result.success) {
|
||||
alert(result.message);
|
||||
window.location.href = 'index.php?action=categories';
|
||||
} else {
|
||||
alert('Ошибка: ' + result.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
<?php
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
session_start();
|
||||
require_once __DIR__ . '/../config/database.php';
|
||||
|
||||
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
||||
header('Location: login.php?error=auth_required');
|
||||
echo json_encode(['success' => false, 'message' => 'Требуется авторизация']);
|
||||
exit();
|
||||
}
|
||||
|
||||
$user_id = $_SESSION['user_id'] ?? 0;
|
||||
|
||||
if ($user_id == 0) {
|
||||
header('Location: login.php?error=user_not_found');
|
||||
echo json_encode(['success' => false, 'message' => 'Пользователь не найден']);
|
||||
exit();
|
||||
}
|
||||
|
||||
@@ -26,8 +27,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$customer_phone = $_POST['phone'] ?? '';
|
||||
$delivery_address = $_POST['address'] ?? '';
|
||||
$region = $_POST['region'] ?? '';
|
||||
$postal_code = $_POST['postal_code'] ?? '';
|
||||
$payment_method = $_POST['payment'] ?? 'card';
|
||||
$delivery_method = $_POST['delivery'] ?? 'courier';
|
||||
$promo_code = $_POST['promo_code'] ?? '';
|
||||
$notes = $_POST['notes'] ?? '';
|
||||
$discount_amount = floatval($_POST['discount'] ?? 0);
|
||||
$delivery_cost = floatval($_POST['delivery_price'] ?? 2000);
|
||||
@@ -63,17 +66,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
INSERT INTO orders (
|
||||
user_id, order_number, subtotal, discount_amount,
|
||||
delivery_price, final_amount, status, payment_method,
|
||||
delivery_method, delivery_address, customer_name,
|
||||
customer_email, customer_phone, notes
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
delivery_method, delivery_address, delivery_region,
|
||||
postal_code, promo_code, customer_name, customer_email,
|
||||
customer_phone, notes
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
RETURNING order_id
|
||||
");
|
||||
|
||||
$orderStmt->execute([
|
||||
$user_id, $order_number, $total_amount, $discount_amount,
|
||||
$delivery_cost, $final_amount, 'pending', $payment_method,
|
||||
$delivery_method, $delivery_address, $customer_name,
|
||||
$customer_email, $customer_phone, $notes
|
||||
$delivery_method, $delivery_address, $region, $postal_code,
|
||||
$promo_code, $customer_name, $customer_email, $customer_phone, $notes
|
||||
]);
|
||||
|
||||
$order_id = $orderStmt->fetchColumn();
|
||||
@@ -109,16 +113,24 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
|
||||
$db->commit();
|
||||
|
||||
header('Location: order_success.php?id=' . $order_id);
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'order_id' => $order_id,
|
||||
'order_number' => $order_number,
|
||||
'message' => 'Заказ успешно оформлен'
|
||||
]);
|
||||
exit();
|
||||
|
||||
} catch (Exception $e) {
|
||||
$db->rollBack();
|
||||
header('Location: checkout.php?error=' . urlencode($e->getMessage()));
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
header('Location: checkout.php');
|
||||
echo json_encode(['success' => false, 'message' => 'Неверный метод запроса']);
|
||||
exit();
|
||||
}
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -876,7 +876,7 @@ try {
|
||||
</h3>
|
||||
<div>
|
||||
|
||||
<a href="admin/index.php?action=catalog" class="admin-btn">
|
||||
<a href="admin/index.php?action=products" class="admin-btn">
|
||||
<i class="fas fa-boxes"></i> Управление каталогом
|
||||
</a>
|
||||
<a href="admin/index.php?action=add_product" class="admin-btn">
|
||||
|
||||
@@ -469,19 +469,23 @@ $(document).ready(function() {
|
||||
url: 'api/process_order.php',
|
||||
method: 'POST',
|
||||
data: $(this).serialize(),
|
||||
success: function(response) {
|
||||
try {
|
||||
const result = JSON.parse(response);
|
||||
if (result.success) {
|
||||
window.location.href = 'order_success.php?id=' + result.order_id;
|
||||
} else {
|
||||
showMessage('Ошибка: ' + result.message, 'error');
|
||||
$('#submit-order').prop('disabled', false).text('ОФОРМИТЬ ЗАКАЗ');
|
||||
}
|
||||
} catch(e) {
|
||||
showMessage('Ошибка обработки заказа', 'error');
|
||||
dataType: 'json',
|
||||
success: function(result) {
|
||||
if (result.success) {
|
||||
showMessage('Заказ успешно оформлен!', 'success');
|
||||
setTimeout(function() {
|
||||
window.location.href = 'cite_mebel.php';
|
||||
}, 1500);
|
||||
} else {
|
||||
showMessage('Ошибка: ' + result.message, 'error');
|
||||
$('#submit-order').prop('disabled', false).text('ОФОРМИТЬ ЗАКАЗ');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX error:', status, error);
|
||||
console.log('Response:', xhr.responseText);
|
||||
showMessage('Ошибка сервера при обработке заказа', 'error');
|
||||
$('#submit-order').prop('disabled', false).text('ОФОРМИТЬ ЗАКАЗ');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -66,7 +66,7 @@ $fullName = $_SESSION['full_name'] ?? $userEmail;
|
||||
<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>
|
||||
<li><a href="admin/index.php?action=products"><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>
|
||||
|
||||
@@ -66,6 +66,66 @@ try {
|
||||
<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>
|
||||
.product__gallery {
|
||||
width: 350px !important;
|
||||
max-width: 350px !important;
|
||||
flex-shrink: 0 !important;
|
||||
}
|
||||
|
||||
.product__main-image {
|
||||
width: 350px !important;
|
||||
height: 350px !important;
|
||||
min-width: 350px !important;
|
||||
min-height: 350px !important;
|
||||
max-width: 350px !important;
|
||||
max-height: 350px !important;
|
||||
background: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
|
||||
display: flex !important;
|
||||
align-items: center !important;
|
||||
justify-content: center !important;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #e9ecef;
|
||||
flex-shrink: 0 !important;
|
||||
}
|
||||
|
||||
.product__main-image img,
|
||||
#mainImage {
|
||||
width: 100% !important;
|
||||
height: 100% !important;
|
||||
max-width: 350px !important;
|
||||
max-height: 350px !important;
|
||||
object-fit: contain !important;
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
.product__section {
|
||||
display: grid !important;
|
||||
grid-template-columns: 350px 1fr !important;
|
||||
gap: 30px;
|
||||
}
|
||||
|
||||
.similar-products .product-image {
|
||||
width: 100% !important;
|
||||
height: 250px !important;
|
||||
max-height: 250px !important;
|
||||
overflow: hidden;
|
||||
background: #f5f5f5;
|
||||
display: flex !important;
|
||||
align-items: center !important;
|
||||
justify-content: center !important;
|
||||
}
|
||||
|
||||
.similar-products .product-image img {
|
||||
width: 100% !important;
|
||||
height: 100% !important;
|
||||
max-width: 100% !important;
|
||||
max-height: 250px !important;
|
||||
object-fit: contain !important;
|
||||
}
|
||||
|
||||
.product-attributes {
|
||||
background: #f8f9fa;
|
||||
padding: 20px;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user