Ежегодно количество интернет


Разработка функции корзина



страница11/19
Дата14.10.2021
Размер1,32 Mb.
1   ...   7   8   9   10   11   12   13   14   ...   19

3.2 Разработка функции корзина

Основной задачей данной функции является добавление выбранного товара в корзину:

$id = clear_string($_GET["id"]);

$action = clear_string($_GET["action"]);
switch ($action) {
case 'clear':

$clear = mysql_query("DELETE FROM cart WHERE cart_ip = '{$_SERVER['REMOTE_ADDR']}'",$link);

break;
case 'delete':

$delete = mysql_query("DELETE FROM cart WHERE cart_id = '$id' AND cart_ip = '{$_SERVER['REMOTE_ADDR']}'",$link);

break;
}
if (isset($_POST["submitdata"]))

{

if ( $_SESSION['auth'] == 'yes_auth' )



{
mysql_query("INSERT INTO orders(order_datetime,order_dostavka,order_fio,order_address,order_phone,order_note,order_email)

VALUES(


NOW(),

'".$_POST["order_delivery"]."',

'".$_SESSION['auth_surname'].' '.$_SESSION['auth_name'].' '.$_SESSION['auth_patronymic']."',

'".$_SESSION['auth_address']."',

'".$_SESSION['auth_phone']."',

'".$_POST['order_note']."',

'".$_SESSION['auth_email']."'

)",$link);


}else

{

$_SESSION["order_delivery"] = $_POST["order_delivery"];



$_SESSION["order_fio"] = $_POST["order_fio"];

$_SESSION["order_email"] = $_POST["order_email"];

$_SESSION["order_phone"] = $_POST["order_phone"];

$_SESSION["order_address"] = $_POST["order_address"];

$_SESSION["order_note"] = $_POST["order_note"];
mysql_query("INSERT INTO orders(order_datetime,order_dostavka,order_fio,order_address,order_phone,order_note,order_email)

VALUES(


NOW(),

'".clear_string($_POST["order_delivery"])."',

'".clear_string($_POST["order_fio"])."',

'".clear_string($_POST["order_address"])."',

'".clear_string($_POST["order_phone"])."',

'".clear_string($_POST["order_note"])."',

'".clear_string($_POST["order_email"])."'

)",$link);

}

$_SESSION["order_id"] = mysql_insert_id();


$result = mysql_query("SELECT * FROM cart WHERE cart_ip = '{$_SERVER['REMOTE_ADDR']}'",$link);

If (mysql_num_rows($result) > 0)

{

$row = mysql_fetch_array($result);


do{
mysql_query("INSERT INTO buy_products(buy_id_order,buy_id_product,buy_count_product)

VALUES(


'".$_SESSION["order_id"]."',

'".$row["cart_id_product"]."',

'".$row["cart_count"]."'

)",$link);


} while ($row = mysql_fetch_array($result));

}
header("Location: cart.php?action=completion");

}

$result = mysql_query("SELECT * FROM cart,table_products WHERE cart.cart_ip = '{$_SERVER['REMOTE_ADDR']}' AND table_products.products_id = cart.cart_id_product",$link);



If (mysql_num_rows($result) > 0)

{

$row = mysql_fetch_array($result);


do

{

$int = $int + ($row["price"] * $row["cart_count"]);



}

while ($row = mysql_fetch_array($result));

$itogpricecart = $int;

}

?>



$('.add-cart-style-list,.add-cart-style-grid,.add-cart,.random-add-cart').click(function(){

var tid = $(this).attr("tid");


$.ajax({

type: "POST",

url: "include/addtocart.php",

data: "id="+tid,

dataType: "html",

cache: false,

success: function(data) {

loadcart();

}

});
});


function loadcart(){

$.ajax({


type: "POST",

url: "include/loadcart.php",

dataType: "html",

cache: false,

success: function(data) {

if (data == "0")

{

$("#block-basket > a").html("Корзина пуста");



}else

{

$("#block-basket > a").html(data);


}

}

});



}



Поделитесь с Вашими друзьями:
1   ...   7   8   9   10   11   12   13   14   ...   19


База данных защищена авторским правом ©psihdoc.ru 2019
обратиться к администрации

    Главная страница