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']) {
|
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':
|
|
|
|
$session_id = ( $_SESSION['user_id'] ) ? $_SESSION['user_id'] : session_id();
|
|
|
|
//Получаем количество, если есть...
|
|
|
|
$kolvo = \DB::getValue( "SELECT `kolvo` FROM `cart` WHERE `user_id`=? AND `tovar_id`=?", array( $session_id, $_POST['pages_id'] ) );
|
|
|
|
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;
|
|
|
|
$cart = \DB::getAll( "SELECT `tovar_id`, `kolvo` FROM `cart` WHERE `user_id`=?", $session_id );
|
|
|
|
for ( $i=0; $i<count( $cart ); $i++ ){
|
|
|
|
$cena = \DB::getValue( "SELECT `cena` FROM `tovar_price_history` WHERE `tovar_id`=? AND `status`=1", $cart[$i]['tovar_id'] );
|
|
|
|
$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:
|
|
|
|
}
|
|
|
|
?>
|