5 changed files with 170 additions and 12 deletions
@ -0,0 +1,42 @@ |
|||||
|
<?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']) |
||||
|
)); |
||||
|
|
||||
|
?> |
||||
|
|
Loading…
Reference in new issue