Skip to content

Commit

Permalink
cart is added
Browse files Browse the repository at this point in the history
  • Loading branch information
bawantha committed Nov 28, 2018
1 parent b052647 commit 7cb8f06
Show file tree
Hide file tree
Showing 5 changed files with 291 additions and 3 deletions.
230 changes: 230 additions & 0 deletions cart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
<?php
session_start();
$con = mysqli_connect("localhost","root","","c_online");
?>
<!DOCTYPE html>
<html>

<head>
<title>C Online </title>

<link href="http://fonts.googleapis.com/css?family=Roboto:400,500,700,300,100" rel="stylesheet" >

<link href="styles/bootstrap.min.css" rel="stylesheet">

<link href="styles/style.css" rel="stylesheet">

<<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">


</head>

<body>


<div class="col-md-9" id="cart" ><!-- col-md-9 Starts -->

<div class="box" ><!-- box Starts -->

<form action="cart.php" method="post" enctype="multipart-form-data" ><!-- form Starts -->

<h1> Shopping Cart </h1>

<?php
if(isset($_SESSION['session_id'])){
$_session_id=$_SESSION['session_id'];
$select_cart ="SELECT * FROM `cart_details` WHERE `session_id`='$_session_id'";
$run_cart = mysqli_query($con,$select_cart);
$count = mysqli_num_rows($run_cart);

}

echo $count;



?>

<p class="text-muted" > You currently have <?php echo $count; ?> item(s) in your cart. </p>

<div class="table-responsive" ><!-- table-responsive Starts -->

<table class="table" ><!-- table Starts -->

<thead><!-- thead Starts -->

<tr>

<th >Product</th>

<th>Quantity</th>

<th>Unit Price</th>

<th >Delete</th>

<th > Sub Total </th>


</tr>

</thead><!-- thead Ends -->

<tbody><!-- tbody Starts -->

<?php

$total = 0;

while($row_cart = mysqli_fetch_array($run_cart)){

$sku_id = $row_cart['sku_id'];

$quantity= $row_cart['quantity'];

$get_products = "SELECT * FROM product NATURAL JOIN sku where sku_id='$sku_id'";

$run_products = mysqli_query($con,$get_products);

while($row_products = mysqli_fetch_array($run_products)){

$product_title = $row_products['product_name'];


$only_price = $row_products['base_price'];

$sub_total = $row_products['base_price']*$quantity;

$total += $sub_total;

?>

<tr>


<td>
<a href="#" > <?php echo $product_title; ?> </a>

</td>

<td>
<?php echo $quantity; ?>
</td>
<td>

<?php echo $only_price; ?>

</td>


<td>
<input type="checkbox" name="remove[]" value="<?php echo $sku_id; ?>" >
</td>

<td>
<?php echo $sub_total?>
</td>


</tr>

<?php } } ?>

</tbody><!-- tbody Ends -->

<tfoot><!-- tfoot Starts -->

<tr>

<th colspan="5"> Total </th>

<th colspan="2"> <?php echo $total; ?></th>

</tr>

</tfoot><!-- tfoot Ends -->

</table><!-- table Ends -->


</div><!-- table-responsive Ends -->


<div class="box-footer"><!-- box-footer Starts -->

<div class="pull-left"><!-- pull-left Starts -->

<a href="index.php" class="btn btn-default">

<i class="fa fa-chevron-left"></i> Continue Shopping

</a>

</div><!-- pull-left Ends -->

<div class="pull-right"><!-- pull-right Starts -->

<button class="btn btn-default" type="submit" name="update" value="Update Cart">

<i class="fa fa-refresh"></i> Update Cart

</button>

<a href="checkout.php" class="btn btn-primary">

Proceed to checkout <i class="fa fa-chevron-right"></i>

</a>

</div><!-- pull-right Ends -->

</div><!-- box-footer Ends -->

</form><!-- form Ends -->


</div><!-- box Ends -->

<?php

function update_cart(){

global $con;

if(isset($_POST['update'])){

foreach($_POST['remove'] as $remove_id){


$delete_product = "delete from cart_details where sku_id='$remove_id'";

$run_delete = mysqli_query($con,$delete_product);

if($run_delete){
echo "<script>window.open('cart.php','_self')</script>";
}



}




}



}

echo @$up_cart = update_cart();



?>





</div><!-- col-md-9 Ends -->
2 changes: 1 addition & 1 deletion controllers/login.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// email and password sent from form

$email = mysqli_real_escape_string($db,$_POST['email']);
$password = md5(mysqli_real_escape_string($db,$_POST['password']));
$password = mysqli_real_escape_string($db,$_POST['password']);

$sql = "SELECT customer_id FROM customer_registered WHERE email = '$email' AND password = '$password' ";
$result = mysqli_query($db,$sql);
Expand Down
2 changes: 1 addition & 1 deletion products.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</p>
</div>
</div>

f
<!-- ITEMS-->
<div class="row">
<div class="box">
Expand Down
58 changes: 58 additions & 0 deletions styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -461,5 +461,63 @@ hr.dotted {
margin-right:5px;
}

#content #cart .table tbody tr td img {
width: 50px;
}

#content #cart .table tbody tr td input {
width: 40px;
text-align: right;

}

#content #cart .table tbody tr td{
vertical-align: middle;

}
#content #cart .table tfoot {
font-size:18px;
}

.box .box-footer {
background: #f7f7f7;
margin: 30px -20px -20px;
padding:20px;
border-top: solid 1px #eeeeee;

}

.box .box-footer:before,
.box .box-footer:after {
content:" ";
display: table;
}

.box .box-footer:after {
clear:both;
}

.box .box-header {
background:#f7f7f7;
margin:-20px -20px 20px;
padding:20px;
border-bottom: solid 1px #eeeeee;

}

#content #order-summary table {
margin-top: 20px;

}
#content #order-summary table td {
color: #999999;
}

#content #order-summary table tr.total td,
#content #order-summary table tr.total th{
font-size: 18px;
color:#555555;
font-weight: 700;

}

2 changes: 1 addition & 1 deletion view.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<input type="number" value="1" min="1" style="width:100px" name="quantity" required><br>

<div class="clearfix">
<button type="submit" class="signupbtn" style="width:200px">Add to Cart</button>
<button type="submit" class="signupbtn" style="width:200px" >Add to Cart</button>
</div>
</div>
</form>
Expand Down

0 comments on commit 7cb8f06

Please sign in to comment.