2022-12-11 13:55:49 +05:00
|
|
|
<?php
|
2022-12-24 21:12:23 +05:00
|
|
|
ini_set('display_errors', 0 );
|
2022-12-11 13:55:49 +05:00
|
|
|
switch(@$_POST['act']) {
|
2023-02-28 21:22:24 +05:00
|
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
27.02.2023
|
|
|
|
Добавляем коментарий
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
case 'addComment':
|
|
|
|
if ($_SESSION['user_id'])\DB::add("INSERT INTO `tovar_otzyv` (`user_id`, `txt`, `t`, `tovar_id`) VALUES (?, ?, ?, ?)", array( $_SESSION['user_id'], nl2br( $_POST['txt'] ), time(), $_POST['tovar_id'] ));
|
|
|
|
break;
|
|
|
|
|
2022-12-17 19:10:16 +05:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
17.12.2022
|
|
|
|
Создаем докмент переоценки + запись в регистр tovar_price_history
|
2022-12-24 21:12:23 +05:00
|
|
|
20.12.2022
|
|
|
|
Товары идут в двухмерный массив
|
2022-12-17 19:10:16 +05:00
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
case 'addChangeCena':
|
2022-12-24 21:12:23 +05:00
|
|
|
$massiv[0]['tovar_id']=$_POST['id'];
|
|
|
|
$massiv[0]['cena']=$_POST['txt'];
|
2022-12-17 19:10:16 +05:00
|
|
|
$json=\json::to_j($massiv);
|
2022-12-24 21:12:23 +05:00
|
|
|
$insert_id = \DB::add( "INSERT INTO `docs` (`t`, `tip`, `json`, `user_id`, `status`, `comment`) VALUES('" . time() . "', 'pereocenka', ?, ?, 1, 'Документ создан из публичной карточки товара')", array($json, $_SESSION['user_id']) );
|
2022-12-17 19:10:16 +05:00
|
|
|
if ($insert_id) \DB::add( "INSERT INTO `tovar_price_history` (`t`, `tovar_id`, `status`, `cena`, `docs_id`) VALUES(?, ?, ?, ?, ?)", array( time(), $_POST['id'], '1', $_POST['txt'], $insert_id ) );
|
|
|
|
break;
|
2022-12-11 13:55:49 +05:00
|
|
|
/* ----------------------------------------------------------------------
|
2022-12-24 21:12:23 +05:00
|
|
|
17.12.2022
|
|
|
|
Добавляем товар в корзину
|
|
|
|
!!! в JS и ACT переделать pages_id на tovar_id !!!
|
2022-12-11 13:55:49 +05:00
|
|
|
---------------------------------------------------------------------- */
|
2022-12-24 21:12:23 +05:00
|
|
|
case 'addToCart':
|
2023-03-11 21:03:29 +05:00
|
|
|
|
|
|
|
|
|
|
|
\DB::set("ALTER TABLE `cart`
|
|
|
|
CHANGE `user_id` `user_id` varchar(50) NULL AFTER `tovar_id`;");
|
|
|
|
|
|
|
|
$session_id = \core::checkMe();
|
2022-12-24 21:12:23 +05:00
|
|
|
//Получаем количество, если есть...
|
2023-07-12 20:02:20 +05:00
|
|
|
$kolvo = \DB::getValue( "SELECT `kolvo` FROM `cart` WHERE `user_id`=? AND `tovar_id`=? AND `order` IS NULL", array( $session_id, $_POST['pages_id'] ) );
|
2022-12-24 21:12:23 +05:00
|
|
|
if ($kolvo){
|
|
|
|
$kolvo=$kolvo+$_POST['kolvo'];
|
|
|
|
\DB::set("UPDATE `cart` SET `kolvo`=? WHERE `user_id`=? AND `tovar_id`=?", array( $kolvo, $session_id, $_POST['pages_id'] ) );
|
|
|
|
}else
|
|
|
|
$insert_id = \DB::add( "INSERT INTO `cart` (`t`, `tovar_id`, `user_id`, `kolvo`) VALUES(?, ?, ?, ?)", array(time(), $_POST['pages_id'], $session_id, $_POST['kolvo'] ) );
|
|
|
|
//Суммируем содержимое корзины и выводим в js
|
|
|
|
$summ = 0;
|
2023-07-12 20:02:20 +05:00
|
|
|
$cart = \DB::getAll( "SELECT `tovar_id`, `kolvo` FROM `cart` WHERE `user_id`=? AND `order` IS NULL", $session_id );
|
2022-12-24 21:12:23 +05:00
|
|
|
for ( $i=0; $i<count( $cart ); $i++ ){
|
2023-07-12 20:02:20 +05:00
|
|
|
$cena = \DB::getValue( "SELECT `cena` FROM `tovar` WHERE `id`=?", $cart[$i]['tovar_id'] );
|
2022-12-24 21:12:23 +05:00
|
|
|
$m = $cena * $cart[$i]['kolvo'];
|
|
|
|
$summ = $summ + $m;
|
2022-12-11 13:55:49 +05:00
|
|
|
}
|
2022-12-24 21:12:23 +05:00
|
|
|
echo $summ;
|
2022-12-11 13:55:49 +05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
?>
|