1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
<?php
session_start();
require_once("cart.php");
$db_handle = new Cart();
if(!empty($_GET["action"])) {
switch($_GET["action"]) {
case "add":
if(!empty($_POST["quantity"])) {
$productByCode = $db_handle->runQuery("SELECT * FROM films WHERE IdFil='" . $_GET["code"] . "'");
$itemArray = array($productByCode[0]["code"]=>array('name'=>$productByCode[0]["Titre"], 'code'=>$productByCode[0]["IdFil"], 'quantity'=>$_POST["quantity"], 'price'=>$productByCode[0]["Prix"],'image'=>$productByCode[0]["Image"]));
//var_dump($itemArray[0]['quantity']);
if(!empty($_SESSION["shop_cart_item"])) {
if(in_array($productByCode[0]["code"],array_keys($_SESSION["shop_cart_item"]))) {
foreach($_SESSION["shop_cart_item"] as $k => $v) {
if($productByCode[0]["code"] == $k) {
if(empty($_SESSION["shop_cart_item"][$k]["quantity"])) {
$_SESSION["shop_cart_item"][$k]["quantity"] = 0;
}
$_SESSION["shop_cart_item"][$k]["quantity"] += $_POST["quantity"];
}
}
} else {
$_SESSION["shop_cart_item"] = array_merge($_SESSION["shop_cart_item"],$itemArray);
}
} else {
$_SESSION["shop_cart_item"] = $itemArray;
}
}
break;
case "remove":
if(!empty($_SESSION["shop_cart_item"])) {
foreach($_SESSION["shop_cart_item"] as $k => $v) {
if($_GET["code"] == $k)
unset($_SESSION["shop_cart_item"][$k]);
if(empty($_SESSION["shop_cart_item"]))
unset($_SESSION["shop_cart_item"]);
}
}
break;
case "empty":
unset($_SESSION["shop_cart_item"]);
break;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- CSS -->
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Bootstrap library -->
<script src="js/bootstrap-4.0.min.js"></script>
<link rel="stylesheet" href="css/bootstrap-4.0.min.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/main.css">
<title>costro | Accueil </title>
</head>
<body class="body">
<div class="txt-heading">Achat </div>
<div class="cart-Panier">
<a id="btnEmpty" href="membre.php?action=empty">Vider le Panier</a>
<?php
if(isset($_SESSION["shop_cart_item"])){
$total_quantity = 0;
$total_price = 0;
?>
<table class="tbl-cart" cellpadding="10" cellspacing="1">
<tbody>
<tr>
<th style="text-align:left;">Nom de</th>
<th style="text-align:left;">Code</th>
<th style="text-align:right;" width="5%">Quantite</th>
<th style="text-align:right;" width="10%">Prix Unitaire</th>
<th style="text-align:right;" width="10%">Prix</th>
<th style="text-align:center;" width="5%">Supprimer</th>
</tr>
<?php
foreach ($_SESSION["shop_cart_item"] as $item){
$item_price = $item["quantity"]*$item["price"];
$_SESSION["Counteur"] = $item["quantity"];
?>
<tr>
<td><img src="img/covers/<?php echo $item["image"]; ?>" class="cart-item-image" width="50" height="70" /><?php echo $item["name"]; ?></td>
<td><?php echo $item["code"]; ?></td>
<td style="text-align:right;"><?php echo $item["quantity"]; ?></td>
<td style="text-align:right;"><?php echo "$ ".$item["price"]; ?></td>
<td style="text-align:right;"><?php echo "$ ". number_format($item_price,2); ?></td>
<td style="text-align:center;"><a href="membre.php?action=remove&code=<?php echo $item["code"]; ?>" class="btnRemoveAction"><i class="icon ion-ios-trash"></i></a></td>
</tr>
<?php
$total_quantity += $item["quantity"];
$total_price += ($item["price"]*$item["quantity"]);
}
?>
<tr>
<td colspan="2" align="right">Total:</td>
<td align="right"><?php echo $total_quantity; ?></td>
<td align="right" colspan="2"><strong><?php echo "$ ".number_format($total_price, 2); ?></strong></td>
<td></td>
</tr>
</tbody>
</table>
<?php
} else {
?>
<div class="no-records">Votre Panier est Vide !</div>
<?php
}
?>
</div>
</div>
<div class="container">
<!-- content tabs -->
<div class="tab-content">
<div class="tab-pane fade show active" id="tab-1" role="tabpanel" aria-labelledby="1-tab">
<div class="row">
<?php
$film_array = $db_handle->runQuery("SELECT * FROM films");
if (!empty($film_array)) {
foreach($film_array as $key=>$value){
?>
<!-- card -->
<div class="col-6 col-sm-4 col-md-3 col-xl-2">
<div class="card">
<a href="javascript:void(0);" data-href="get-film.php?id=<?php echo $film_array[$key]['IdFil'];?>" class="openPopup">
<div class="card__cover">
<img src="img/covers/<?php echo $film_array[$key]['Image']; ?>" alt="">
<span class="card__rate card__rate--green">8.4</span>
</div>
<div class="card__content">
<form method="post" action="membre.php?action=add&code=<?php echo $film_array[$key]['IdFil']; ?>">
<h3 class="card__title"><a href="#"><?php echo $film_array[$key]['Titre']; ?></a></h3>
<span class="card__category">
<a href="#"><?php echo $film_array[$key]['Realisateur']; ?></a>
<a href="#"><?php echo $film_array[$key]['Categorie']; ?></a>
<input type="text" class="product-quantity" name="quantity" value="1" size="2" />
<input type="submit" value="Ajouter" class="btnAddAction" />
</span>
</form>
</div>
</a>
</div>
</div>
<!-- end card -->
<?php
}
}?>
</div>
</div>
</div>
<!-- end content tabs -->
</div>
</section>
<!-- end content -->
</body>
</html> |