core/api/modules/cart/ajax.php

47 lines
2.4 KiB
PHP
Raw Normal View History

2022-12-11 13:55:49 +05:00
<?php
2023-03-11 21:03:29 +05:00
ini_set( 'display_errors', 1 );
2022-12-24 21:12:23 +05:00
switch( @$_POST['act'] ) {
case 'change-kolvo':
$session_id = ( $_SESSION['user_id'] ) ? $_SESSION['user_id'] : session_id();
\DB::set( "UPDATE `cart` SET `kolvo`=? WHERE `id`=? AND `user_id`=?", array( $_POST['kolvo'], $_POST['id'], $session_id ) ) ;
$res=\core::getCart();
echo $res['summ'];
2022-12-11 13:55:49 +05:00
break;
2022-12-24 21:12:23 +05:00
case 'del-from-cart':
$session_id = ( $_SESSION['user_id'] ) ? $_SESSION['user_id'] : session_id();
\DB::set( "DELETE FROM `cart` WHERE `id`=? AND `user_id`=?", array( $_POST['id'], $session_id ) ) ;
$res=\core::getCart();
echo $res['summ'];
2022-12-11 13:55:49 +05:00
break;
2022-12-24 21:12:23 +05:00
2023-03-11 21:03:29 +05:00
/* ----------------------------------------------------------------------
06.03.2023
Простое оформление заказа на зарегистрированного физ лица
---------------------------------------------------------------------- */
case 'zakazFz':
if (!$_SESSION['user_id'])die("403");
//Создаем заказ
$insert_id=\DB::add("INSERT INTO `orders` (`user_id`, `status`, `t`) VALUES (?, ?, ?)", array($_SESSION['user_id'], 0, time()));
//обновляем данные в корзине
\DB::set("UPDATE `cart` SET `order`=? WHERE `user_id`=? AND `order` IS NULL", array($insert_id, $_SESSION['user_id']));
break;
/* ----------------------------------------------------------------------
11.03.2023
Простое оформление заказа на НЕ зарегистрированного физ лица
---------------------------------------------------------------------- */
case 'zakazFzAnonim':
$user=\core::checkMe();
if ( $db['type'] == 'mysql' ) \DB::alterTable( "ALTER TABLE `orders` ADD `email` varchar(254) COLLATE 'utf8_general_ci' NULL" );
if ( $db['type']=='sqlite3' ) \DB::alterTable( "ALTER TABLE `orders` ADD `email` TEXT" );
//Создаем заказ
$insert_id=\DB::add("INSERT INTO `orders` (`user_id`, `status`, `t`, `fio`, `tel`, `email`) VALUES (?, ?, ?, ?, ?, ?)", array($user, 0, time(), $_POST['fio'], $_POST['tel'], $_POST['email'] ));
//обновляем данные в корзине
\DB::set("UPDATE `cart` SET `order`=? WHERE `user_id`=? AND `order` IS NULL", array($insert_id, $user));
break;
2022-12-11 13:55:49 +05:00
default:
}
?>