Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/ecommerce1.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions admin/del_order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
include ('functions/db_connect.php');
if(isset($_GET['del']))
{
$id=$_GET['del'];
$sql= "DELETE FROM `cart` WHERE `p_id` = $id";
$run =mysqli_query($con,$sql);
if($run)
{
echo '<script>alert("Deleted Successfully");</script>';
header("refresh:2;URL=index.php?view_orders");
}
else
{
echo '<script>alert("Error while deleting order");</script>';
}
}


?>
128 changes: 128 additions & 0 deletions admin/functions/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php

//getting Categories
function getCats(){
global $con;
$get_cats = "select * from categories";
$run_cats = mysqli_query($con, $get_cats);
while ($row_cats= mysqli_fetch_array($run_cats)){
$cat_id = $row_cats['cat_id'];
$cat_title = $row_cats['cat_title'];
echo "<li><a href='index.php?cat=$cat_id'> $cat_title </a></li>";
}
}

//getting Brands
function getBrands(){
global $con;
$get_brands = "select * from brands";
$run_brands = mysqli_query($con, $get_brands);
while ($row_brands= mysqli_fetch_array($run_brands)){
$brand_id = $row_brands['brand_id'];
$brand_title = $row_brands['brand_title'];
echo "<li><a href='index.php?brand=$brand_id'> $brand_title </a></li>";
}
}

function getPro($flag = ''){
global $con;
$get_pro = "";
if(!isset($_GET['cat']) && !isset($_GET['brand']) && !isset($_GET['search'])) {
if($flag == 'all_products')
$get_pro = "select * from products";
else
$get_pro = "select * from products order by RAND() limit 0,6";
} else if(isset($_GET['cat'])){
$pro_cat_id = $_GET['cat'];
$get_pro = "select * from products where pro_cat = '$pro_cat_id'";
} else if(isset($_GET['brand'])){
$pro_brand_id = $_GET['brand'];
$get_pro = "select * from products where pro_brand = '$pro_brand_id'";
} else if(isset($_GET['search'])){
$search_query = $_GET['user_query'];
$get_pro = "select * from products where pro_keywords like '%$search_query%'";
}
$run_pro = mysqli_query($con,$get_pro);
$count_pro = mysqli_num_rows($run_pro);
if($count_pro==0){
echo "<h2> No Product found in selected criteria </h2>";
}
while($row_pro = mysqli_fetch_array($run_pro)){
$pro_id = $row_pro['pro_id'];
$pro_cat = $row_pro['pro_cat'];
$pro_brand = $row_pro['pro_brand'];
$pro_title = $row_pro['pro_title'];
$pro_price = $row_pro['pro_price'];
$pro_image = $row_pro['pro_image'];
echo "
<div class='single_product'>
<h3>$pro_title</h3>
<img src='admin/product_images/$pro_image' width='180' height='180'>
<p> <b> Rs $pro_price/- </b> </p>
<a href='details.php?pro_id=$pro_id' style='float: left'>Details</a>
<a href='index.php?add_cart=$pro_id'><button style='float: right;'>Add to Cart</button></a>
</div>
";
}
}
//getting the user IP address
function getIp() {
$ip = $_SERVER['REMOTE_ADDR'];

if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
return $ip;
}
//creating the shopping cart
function cart(){
if(isset($_GET['add_cart'])){
global $con;
$ip = getIp();
$pro_id = $_GET['add_cart'];
$check_pro = "select * from cart where ip_add = '$ip' AND p_id='$pro_id '";
$run_check = mysqli_query($con,$check_pro);
if(mysqli_num_rows($run_check)>0){
echo "";
} else {
$insert_pro = "insert into cart (p_id, ip_add) VALUES
('$pro_id','$ip')";
$run_pro = mysqli_query($con,$insert_pro);
if($run_pro)
header('location:'.$_SERVER['PHP_SELF']);
}
}
}
//getting the total added items.
function total_items(){
global $con;
$ip = getIp();
$get_items = "select * from cart where ip_add='$ip'";
$run_items = mysqli_query($con,$get_items);
$count_items = 0;
while($row = mysqli_fetch_array($run_items))
$count_items += $row['qty'];
echo $count_items;
}
//getting the total price of the items in the cart
function total_price(){
global $con;
$ip = getIp();
$total = 0;
$sel_price = "select * from cart where ip_add = '$ip'";
$run_price = mysqli_query($con,$sel_price);
while($cart_row = mysqli_fetch_array($run_price)){
$pro_id = $cart_row['p_id'];
$pro_qty = $cart_row['qty'];
$pro_price = "select * from products where pro_id = '$pro_id'";
$run_pro_price = mysqli_query($con, $pro_price);
while ($pro_row = mysqli_fetch_array($run_pro_price)){
$pro_price = $pro_row['pro_price'];
$pro_price_all_items = $pro_price * $pro_qty;
$total += $pro_price_all_items;
}
}
echo 'Rs '.$total.'/-';
}
3 changes: 3 additions & 0 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
else if(isset($_GET['del_customer'])){
include ('del_customer.php');
}
else if(isset($_GET['view_orders'])){
include ('view_orders.php');
}


?>
Expand Down
52 changes: 52 additions & 0 deletions admin/view_order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<div class="row">
<div class="col-sm-12">
<h1>Products</h1>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Title</th>
<th scope="col">Image</th>
<th scope="col">Price</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<?php
$get_pro = "select * from products";
$run_pro = mysqli_query($con,$get_pro);
$count_pro = mysqli_num_rows($run_pro);
if($count_pro==0){
echo "<h2> No Product found in selected criteria </h2>";
}
else {
$i = 0;
while ($row_pro = mysqli_fetch_array($run_pro)) {
$pro_id = $row_pro['pro_id'];
$pro_cat = $row_pro['pro_cat'];
$pro_brand = $row_pro['pro_brand'];
$pro_title = $row_pro['pro_title'];
$pro_price = $row_pro['pro_price'];
$pro_image = $row_pro['pro_image'];
?>
<tr>
<th scope="row"><?php echo ++$i; ?></th>
<td><?php echo $pro_title; ?></td>
<td><img class="img-thumbnail" src='product_images/<?php echo $pro_image;?>' width='80' height='80'></td>
<td><?php echo $pro_price; ?>/-</td>
<td><a href="index.php?edit_pro=<?php echo $pro_id?>" class="btn btn-primary">
<i class="fa fa-edit"></i> Edit
</a>
<a href="index.php?del_pro=<?php echo $pro_id?>" class="btn btn-danger">
<i class="fa fa-trash-alt"></i> Delete
</a>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
</div>
96 changes: 96 additions & 0 deletions admin/view_orders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!DOCTYPE html>
<?php
session_start();
require "functions/functions.php";
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Online Shop</title>
<link rel="stylesheet" type="text/css" href="css/mystyle.css">
</head>
<body>
<h1>Orders</h1>
<div id="content_area">
<?php
global $con;
$ip = getIp();
if(isset($_POST['update_cart'])){
/*Way 1 to do */
//foreach (array_combine($_POST['product_id'], $_POST['qty']) as $pro_id => $qty) {
/*Way 2 to do */
for($i =0; $i< sizeof($_POST['product_id']); $i++){
$pro_id = $_POST['product_id'][$i];
$qty = $_POST['qty'][$i];
if($qty > 0) {
$update_qty = "update cart set qty='$qty' where p_id='$pro_id' AND ip_add='$ip'";
$run_qty = mysqli_query($con, $update_qty);
}
}
if(isset($_POST['remove'])) {
foreach ($_POST['remove'] as $remove_id) {
$del_pro = "delete from cart where p_id='$remove_id' AND ip_add='$ip'";
$run_del = mysqli_query($con, $del_pro);
}
}
header('location: '.$_SERVER['PHP_SELF']);
}
if(isset($_POST['continue'])){
header('location: index.php');
}
?>
<div class="products_box">
<br>
<form action="" method="post" enctype="multipart/form-data">
<table class="table table-striped">
<tr align="center">
<th> Product(s) </th>
<th> Quantity </th>
<th> Unit Price </th>
<th> Items Total </th>
<th> Actions </th>
</tr>
<?php
$ip = getIp();
$total = 0;
$sel_price = "select * from cart where ip_add = '$ip'";
$run_price = mysqli_query($con,$sel_price);
while($cart_row = mysqli_fetch_array($run_price)){
$pro_id = $cart_row['p_id'];
$pro_qty = $cart_row['qty'];
$pro_price = "select * from products where pro_id = '$pro_id'";
$run_pro_price = mysqli_query($con, $pro_price);
while ($pro_row = mysqli_fetch_array($run_pro_price)){
$pro_title = $pro_row['pro_title'];
$pro_image = $pro_row['pro_image'];
$pro_price = $pro_row['pro_price'];
$pro_price_all_items = $pro_price * $pro_qty;
$total += $pro_price_all_items;
?>
<tr align="center">
<td><?php echo $pro_title; ?>
<br>
<img src="product_images/<?php echo $pro_image; ?>"width="60" height="60">
</td>
<td><lable size="2"><?php echo $pro_qty;?></lable>
<input name="product_id[]" type="hidden" value="<?php echo $pro_id;?>">
</td>
<td><?php echo "Rs " . $pro_price . "/-"; ?></td>
<td><?php echo "Rs " . $pro_price_all_items . "/-"; ?></td>
<td><a href="del_order.php?del=<?php echo"$pro_id" ?>" class="btn btn-danger">
<i class="fa fa-trash-alt"></i> Delete
</a>
</td>
</tr>
<?php
}
}
?>
<tr align="right">
<td colspan="3" align="center"><b>Sub Total:</b></td>
<td colspan="2" align="center"><?php echo "Rs ".$total."/-"; ?></td>
</tr>
</table>
</form>
</body>
</html>