ПЗ к интернет-магазину. поянительная записка к курсовой работе интернет-магазин. Ежегодно количество интернет
Скачать 1.32 Mb.
|
РАЗРАБОТКА ПРОГРАММНЫХ МОДУЛЕЙ3.1 Разработка функции сортировкиОсновной задачей данной функции является упорядочивания товаров в каталоге. Исходный код данного метода приведен ниже: $sorting = $_GET["sort"]; switch ($sorting) { case 'price-asc'; $sorting = 'price ASC'; $sort_name = 'От дешевых к дорогим'; break; case 'price-desc'; $sorting = 'price DESC'; $sort_name = 'От дорогих к дешевым'; break; case 'popular'; $sorting = 'count DESC'; $sort_name = 'Популярное'; break; case 'news'; $sorting = 'datetime DESC'; $sort_name = 'Новинки'; break; case 'brand'; $sorting = 'brand'; $sort_name = 'Новинки'; break; default: $sorting = 'products_id DESC'; $sort_name = 'Нет сортировки'; break; } ?> 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); } } }); } |