Bonjour a tous,
Je suis désolés, la question a du être posée 1000 fois et même si GG est mon ami, je ne parviens pas a adapter mon code et le transformer avec une class panier.
Je m’explique.
Récemment j'étais hébergé sous php4 et mon script de panier fonctionnait parfaitement, ais depuis que mon hébergeur est passé en PHP, plus aucune session ne tient !!
Voici mon code :
index.php
page.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 <? if( isset($_SESSION['panier'])){$panier = $_SESSION['panier']; $totcde=0; echo '<div class="divpanier"><a href="panier.php" target="_blank" title="Mon Panier contient : '.$valeur.'">';require('inc_connect.php');foreach ($panier as $valeur=>$cde){$totcde+=$cde;}echo $totcde.'</a></div>';}?>
le fichier panier.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 if(isset($_POST['action']) and $_POST['action']=="Commander") { $idP=$_POST['idP']; $qte=$_POST['qte']; if( empty($panier[$idP])){$panier[$idP]=$qte;} else{$panier[$idP]+=$qte;} } if(isset($_POST['action']) and $_POST['action']=='Eliminer') { if(empty($_POST['case']) ){exit;} foreach ($_POST['case'] as $delete){unset($panier[$delete]);}?><script ="Javascript">location.replace('panier.php');</script><? exit;} if(isset($_POST['action']) and $_POST['action']=='Changer') { if(empty($_POST['case']) ){exit;}?> <form method="POST" action=""><? require('inc_connect.php'); foreach($_POST['case'] as $modif) { $sql="Select* from produits where idP='$modif'"; $req=mysql_query($sql,$connexion) or exit ('Erreur SQL !'.$sql.'<br>'.mysql_error()); while( $data=mysql_fetch_array($req) ) {echo"<b>Produit :</b> <i>".$data['nom']."</i><br><b>Quantité commandée :</b> <input type='text' name='exqte[$modif]' value='".$panier[$modif]."' size='2'><hr>"; } } mysql_close();?> <input type="submit" name="action" value="OK"> </form> <? } if(isset($_POST['action']) and $_POST['action']=='OK') { if(empty($_POST['exqte']) ){exit;} foreach ($_POST['exqte'] as $type =>$nbre) { if( $nbre==0 or empty($nbre)) { unset($panier[$type]); } $panier[$type]=$nbre; }?> <script ="Javascript">location.replace('panier.php');</script><? exit;} $panier = $panier; echo "panier : $panier<br>";
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?php include ('config.php'); session_start(); if(isset($_POST['action']) and $_POST['action']=='Supprimer') { if(empty($_POST['case']) ) { echo '<script ="Javascript">history.go(-1);</script>'; exit; } foreach ($_POST['case'] as $delete) { unset($_SESSION['panier'][$delete]); } echo '<script ="Javascript">location.replace(\'panier.php\');</script>'; exit; } if(isset($_POST['action']) and $_POST['action']=='Vider mon Panier'){ session_destroy(); header("Location: http://www.nomdusite.com"); } ?> <br><br> <?php if( isset($_SESSION['panier'])) { $panier = $_SESSION['panier']; $tot=0; echo ' <form action="panier.php" method="post"> <section class="cart-section cart-section_cart-listing"> <header><h2>Vos Achats sur xxxxxx.com</h2></header> <table class="table table-bordered cart-summary"> <thead> <th class="table-column__name">Produit</th> <th class="table-column__sku">Reference</th> <th class="table-column__price">Prix</th> <th class="table-column__qty">Quantité</th> <th class="table-column__total">Total</th> <th class="table-column__tax">Supprimer</th> </thead> <tbody>'; require(connect.php'); $totref="";$totnom=""; foreach ($panier as $valeur=>$cde) { $req=mysql_query("select * from prod where idP='$valeur'"); while( $data=mysql_fetch_array($req) ) { $titre=$data['titre'];$photo=$data['photo'];$prix=$data['prix'];$pxligne=$prix*$cde; $tot+=$pxligne; $refsour=$data['ref_source'];$totref.=$refsour.'['.$cde.'] + '; $nomsour=$data['titre'];$totnom.=$nomsour.'['.$cde.'] + '; echo '<tr class="cart-product"> <td data-title="Nom Produit" class="cart-product_name"><div class="product-image"><img src="'.$photo.'" alt="'.$titre.'" style=""/></div> <span class="product-name"><a href="" >'.$titre.'</a></span></td> <td data-title="Reference" class="cart-product_sku">'.$data['ref_source'].'</td> <td data-title="Prix" class="cart-product_price"><div class="PricesalesPrice vm-display vm-price-value"><span class="vm-price-desc"></span> <span class="PricesalesPrice">'.$prix.'</span></div></td> <td data-title="Quantité" class="cart-product_qty"><div class="qty-control">'.$cde.'</div></td> <td data-title="Soustotal" class="cart-product_total"><div class="PricesalesPrice vm-display vm-price-value"><span class="vm-price-desc"></span> <span class="PricesalesPrice">'; $pxligne=number_format($pxligne, 2,'.',' '); echo ''.$pxligne.'</span></div> </td> <td data-title="Supprimer" class="cart-product_tax"><input type="checkbox" name="case[]" value="'.$data['idP'].'"> <input type="submit" name="action" value="Supprimer"></td> </tr>'; } } echo '</tbody>'; echo '<tbody> <tr class="cart-product"> <td data-title="Total" class="cart-product_name" colspan="4"><span class="product-name">Total</span></td> <td data-title="" class="cart-product_total"><div class="PricesalesPrice vm-display vm-price-value"><span class="vm-price-desc"></span> <span class="PricesalesPrice">'; $tot=number_format($tot, 2,'.',' '); echo '<b>'.$tot.'</b></span></div></td> <td data-title="" class="cart-product_tax"></td> </tr>'; echo '</tbody> </table> </section> <br><input type="submit" name="action" value="Vider mon Panier"> </form>'; } echo '<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1">'; $i=0; foreach ($panier as $valeur=>$cde) { $i=$i+1; $req=mysql_query("select * from prod where idP='$valeur'"); while( $data=mysql_fetch_array($req) ) { $titre=$data['titre'];$photo=$data['photo'];$prix=$data['prix'];$pxligne=$prix*$cde; $tot+=$pxligne; $refsour=$data['ref_source'];$totref.=$refsour.'['.$cde.'] + '; $nomsour=$data['titre'];$totnom.=$nomsour.'['.$cde.'] + '; echo '<input name="amount_'.$i.'" type="hidden" value="'.$prix.'"/> <input name="quantity_'.$i.'" type="hidden" value="'.$cde.'"/> <input name="item_name_'.$i.'" type="hidden" value="'.$titre.'"/> <input name="item_number_'.$i.'" type="hidden" value="'.$refsour.'"/>'; $i=$i; } } echo ' <input name="currency_code" type="hidden" value="EUR" /> <input name="shipping" type="hidden" value="9.50" /> <input name="tax" type="hidden" value="0.00" /> <input name="return" type="hidden" value="http://www.xxxxxx.com/paypal-confirmation.php" /> <input name="cancel_return" type="hidden" value="http://www.xxxxxx.com/panier.php" /> <input name="notify_url" type="hidden" value="http://www.xxxxxx.com/paypal-remerciement.php" /> <input name="business" type="hidden" value="xxxxxx@hotmail.fr" /> <input name="lc" type="hidden" value="FR" /> <input name="bn" type="hidden" value="PP-BuyNowBF" /> <section class="cart-section cart-section__login"> <header><h2>Payer mon Panier</h2></header> <div class="cart_login"> <div class="container2"> <div class="row"> <div class="col-lg-8 col-md-8 col-sm-6 col-xs-12"> <div class="row"> <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"> <input alt="Effectuez vos paiements via PayPal : une solution rapide, gratuite et sécurisée" name="submit" src="https://www.paypal.com/fr_FR/FR/i/btn/btn_buynow_LG.gif" type="image" /><img src="https://www.paypal.com/fr_FR/i/scr/pixel.gif" border="0" alt="" width="1" height="1" /> </div> </div> </div> </div> </div> </div> </section> </form> '; ?>
J'ai donc tenté de passer par une class, mais avec tout mon code modifié ci-dessus, je me perds complétement :
MERCI MILLLLLLES FOIS a ceux qui prendront le temps de me lire et pourront m'aider, il est 6h48 bon courage a tous pour cette journée
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?php class Panier { private $prixTotal; private $produit; public function __construct() { $this->prixTotal = 0; $this->produit = array(); } public function getPrixTotal() { return $this->prixTotal; } public function getProduit() { return $this->produit; } public function getNombreProduit() { return count($this->produit); } public function setPrixTotal($prix) { $this->prixTotal = $prix; } public function addProduit($id, $nombre) { $requete = mysql_query("SELECT * FROM prod WHERE idP='".$id."'"); $donnees = mysql_fetch_array($requete); $this->prixTotal += $donnees['prix']*$nombre; $this->produit[$this->getNombreProduit()] = array($id, $nombre); } public function __destruct() { } } ?>
Olivier
Partager