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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
| <?php
require_once('inc/init.inc.php');
//J'ai testé de cette façon mais ça ne me rajoute plus la quantité dans mon panier depuis la fiche article.
// if(!empty($_POST))
// {
// header('Location:panier.php');
// exit;
// }
require_once('inc/haut_de_site.inc.php');
?>
<!-- Script pour les CGV -->
<script type="text/javascript">
//<![CDATA[
function checkFormCGV() {
if(!document.getElementById("cgv-checkbox").checked) {
document.getElementById("erreur-cgv").innerHTML = "Vous devez accepter les conditions générales de vente";
return false;
}
}
//]]>
</script>
<?php
creationDuPanier(); //crée le panier au cas où il ne l'est pas.
if(isset($_POST['ajout_panier']))//ce post provient de la page reservation_details.php
{
$resultat = informationSurUnArticle($_POST['id_article']); //on renseigne l'argument de ma fonction par le $_POST['id_salle'] récupéré depuis la reservation_details.php
$resultat_promo = informationSurUnePromotion($_POST['id_article']);
$article = $resultat->fetch_assoc();
$promo = $resultat_promo->fetch_assoc();
ajouterArticleDansPanier($article['id_article'],$article['titre'],$article['photo'],$article['prix'],$_POST['quantite'],$promo['id_promo'], $promo['reduction']);
}
#----------DEBUT VIDER LE PANIER----------
if(isset($_GET['action']) && $_GET['action'] == 'vider')
{
unset($_SESSION['panier']);
}
#----------DEBUT RETIRER ARTICLE DU PANIER----------
if(isset($_GET['action']) && $_GET['action'] == 'retirer')
{
retirerArticleDuPanier($_GET['id_article']);
header("location:panier.php");
exit();
}
#----------VERIFICATION CODE PROMO----------
if( isset($_POST['validation_codePromo'])){
for($i = 0; $i < count($_SESSION['panier']['id_article']) ; $i++){
$query = executeRequete("SELECT * FROM article ar, promotion prom WHERE prom.id_promo = ar.id_promo AND '$_POST[code_promoPanier]' = prom.code_promo AND '".$_SESSION['panier']['id_article'][$i]."' = ar.id_article");
}
$verif_promo = $query->fetch_assoc();
}
if(!empty($_POST['code_promoPanier']) && isset($_POST['validation_codePromo'])){
$query_code = executeRequete("SELECT id_article, code_promo, ar.id_promo, reduction FROM promotion prom, article ar WHERE '$_POST[code_promoPanier]' = prom.code_promo AND ar.id_article IN (".implode(",", $_SESSION['panier']['id_article'] )." ) AND ar.id_promo = prom.id_promo");
$resultat_queryCode = $query_code->fetch_assoc();
}
#----------PARTIE PAIEMENT DU PANIER----------
// debug($_SESSION);
echo '<section>';
if(isset($_POST['payer']) && $_POST['payer'])
{
//boucle qui tourne autant de fois qu'il y a d'articles différents dans le panier :
for($i = 0; $i < count($_SESSION['panier']['id_article']) ; $i++)
//cf. count() équivalent du sizeof() => http://php.net/manual/fr/function.sizeof.php
{
$resultat = informationSurUnArticle($_SESSION['panier']['id_article'][$i]);
$article = $resultat->fetch_assoc();
#verification du stock : (on est toujours dans la boucle dont le but est de nous retourner le contenu du panier)
if($article['stock'] < $_SESSION['panier']['quantite'][$i]) //si le stock actuel est strictement inférieur à la quantité que l'on souhaite commander...=>PROBLEME !!!
{
echo '<hr><div class="erreur">Stock restant : ' . $article['stock'] . '</div>';
echo '<div class="erreur">Quantité demandée : ' .$_SESSION['panier']['quantite'][$i] . '</div>';
if($article['stock'] > 0)
{
echo '<div class="erreur">la quantité de l\'article ' . $_SESSION['panier']['id_article'][$i] . ' a été réduite car notre stock était insuffisant. Veuillez vérifier vos achats</div>';
$_SESSION['panier']['quantite'][$i] = $article['stock'];
}
else //rupture de stock : on retire carrément les articles du panier.
{
echo '<div class="erreur">l\'article ' . $_SESSION['panier']['id_article'][$i] . ' a été retiré de votre panier car nous sommes en rupture de stock, veuilliez vérifier vos achats.</div>';
retirerArticleDuPanier($_SESSION['panier']['id_article'][$i]); //on retire l'article.
$i--; //on décrémente pour retirer un article. Lorsque l'on souhaite rajouter une valeur à notre variable on incrémente, ici on souhaite enlever une valeur du coup on décrémente.
}
$erreur = TRUE;
}
}
if(!isset($erreur)) //si $erreur = FALSE => on enregistre le panier.
{
if(montantTotal() < 50){
$montantPanier = (montantTotal()+4.50);
}
if(montantTotal() > 50){
$montantPanier = montantTotal();
}
executeRequete("INSERT INTO commande(id_membre,montant,date) VALUES (" . $_SESSION['utilisateur']['id_membre'] . "," . montantTotal() . ", NOW())");
$id_commande = $mysqli->insert_id;
for($j = 0 ; $j < count($_SESSION['panier']['id_article']); $j++)
{
executeRequete("INSERT INTO details_commande (id_commande,id_article,quantite,prix) VALUES ($id_commande, ". $_SESSION['panier']['id_article'][$j] . "," . $_SESSION['panier']['quantite'][$j] . ",". $_SESSION['panier']['prix'][$j]. ")");
executeRequete("UPDATE article SET stock=stock-".$_SESSION['panier']['quantite'][$j] . " WHERE id_article=" . $_SESSION['panier']['id_article'][$j]);
}
unset($_SESSION['panier']);
// mail($_SESSION['utilisateur']['email'],"Confirmation de la commande", "Votre suivi de commande est le suivante : $id_commande","From:confirmation@hus.com");
echo "<div class='validation'>Merci pour votre commande. Votre n° de suivi est le $id_commande</div>";
}
}
//------AFFICHAGE DU PANIER------
echo $msg;
echo"<div id='check1'>";
echo"<div class='checkout_road'>
<img src='". RACINE_SITE ."photo/line1.png' alt='' title=''>
<h2>1. Panier</h2>
</div>";
echo "<table id='tab_panier' border='1' style='border-collapse:collapse' cellpadding='5'>";
//Proposer au visteur de vider son panier :
echo '<tr><th colspan="4" id="titre_tableau">VOTRE PANIER</th><td colspan="1"><a href="?action=vider">Vider le panier</a></td></tr>';
echo "<tr><th>Photo</th><th>Article</th><th>Quantité</th><th>Prix TTC</th><th>Action</th></tr>";
//Condition : si le panier est vide :
if(empty($_SESSION['panier']['id_article']))
{
echo '<tr><td colspan="10" id="empty_cart">Votre panier est vide</td></tr>';
}
else
{
$i = 0;
for($w = 0; $w < count($_SESSION['panier']['id_article']); $w++) //boucle qui tournera autant de fois qu'il y a d'articles dans notre panier
{
$css_class = ($i % 2 == 0) ? 'clair' : 'sombre';
echo '<tr class="'.$css_class.'">';
echo "<td><img class='img_articlePanier' src='" . $_SESSION['panier']['photo'][$w] . "' alt='". $_SESSION['panier']['titre'][$w] . "' title='". $_SESSION['panier']['titre'][$w] . "' ></td>";
echo "<td>" . $_SESSION['panier']['titre'][$w] . "</td>";
echo "<td>" . $_SESSION['panier']['quantite'][$w] . "</td>";
if($_SESSION['panier']['id_promo'][$w] > 1){
echo "<td>" . ($_SESSION['panier']['prix'][$w] - ($_SESSION['panier']['prix'][$w] *($_SESSION['panier']['reduction'][$w]/100))) . " </td>";
}
else{
echo "<td>" . $_SESSION['panier']['prix'][$w] . " </td>";
}
echo "<td><a href='?action=retirer&id_article=" . $_SESSION['panier']['id_article'][$w] . "'><img src='". RACINE_SITE . "photo/suppr.png' alt='' title='Supprimer cet article'></a></td>";
echo "</tr>";
$i++;
}
echo "<tr class='border_stop'><td colspan='3'></td><th colspan='1' class='border_prix'>Prix Total TTC :</th><td colspan='1'>" . montantSousTotal() . " </td></tr>";
}
echo "</table>";
if(!empty($_SESSION['panier']['id_article'])){
echo "<div><a id='return_btn' href='" . RACINE_SITE . "panier_adresse.php'>Passer à l'étape suivante</a></div>";
}
echo "</div>";
require_once('inc/footer.inc.php'); |
Partager