Add .gitignore and project files
This commit is contained in:
31
update_cart.php
Normal file
31
update_cart.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'config/database.php';
|
||||
|
||||
if (!isset($_SESSION['isLoggedIn']) || $_SESSION['isLoggedIn'] !== true) {
|
||||
echo json_encode(['success' => false, 'message' => 'Требуется авторизация']);
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['product_id'])) {
|
||||
$product_id = intval($_POST['product_id']);
|
||||
$quantity = intval($_POST['quantity'] ?? 1);
|
||||
$user_id = $_SESSION['user_id'] ?? 0;
|
||||
|
||||
$db = Database::getInstance()->getConnection();
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare("
|
||||
UPDATE cart
|
||||
SET quantity = ?, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE user_id = ? AND product_id = ?
|
||||
");
|
||||
$stmt->execute([$quantity, $user_id, $product_id]);
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
echo json_encode(['success' => false, 'message' => 'Ошибка базы данных']);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user