You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.0 KiB
42 lines
1.0 KiB
<?php
|
|
session_start();
|
|
session_id(trim($_GET['sid']));
|
|
include_once './config.php';
|
|
include_once './database.php';
|
|
|
|
header("Access-Control-Allow-Origin: *");
|
|
header("Content-Type: application/json; charset=UTF-8");
|
|
header("Access-Control-Allow-Methods: POST");
|
|
header("Access-Control-Max-Age: 3600");
|
|
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
|
|
|
$databaseService = new DatabaseService();
|
|
$conn = $databaseService->getConnection();
|
|
|
|
$pid = trim($_POST['pid']);
|
|
$price = trim($_POST['price']);
|
|
$qty = trim($_POST['qty']);
|
|
|
|
$exists = false;
|
|
|
|
foreach($_SESSION['CART'] as $k => $item) {
|
|
if($item['pid'] == $pid) {
|
|
$_SESSION['CART'][$k]['qty'] += intval($qty);
|
|
$exists = true;
|
|
}
|
|
}
|
|
|
|
if(!$exists) {
|
|
$_SESSION['CART'][] = array("pid" => intval($pid), "price" => intval($price), "qty" => intval($qty));
|
|
}
|
|
|
|
//print_r($_SESSION['CART']);
|
|
http_response_code(200);
|
|
echo json_encode(
|
|
array(
|
|
"status" => 200,
|
|
"cart" => array_values($_SESSION['CART'])
|
|
));
|
|
|
|
?>
|
|
|