Page 1 sur 1

Problème Php : Undifined Index ..

Posté : 01 juil. 2015, 07:38
par Othy
Bonjour les amis :

Je suis encore débutant en PHP et je travail sur la conception d'un site internet E-commerce ..pour un projet de fin d'études

J'ai un problème avec la tva ( elle se calcule est s'affiche correctement sur la bd lorsque je rentre un article comme Admin ) mais lorsque j'ajoute un article au panier ça s'affiche pas


Notice: Undefined index: tva in C:\wamp\www\Site e-Commerce\include\fonctions_panier.php on line 159

153 function montantGlobaltva(){
154 $total = 0;
155 for($i = 0; $i < count($_SESSION['panier']['titreProduit']); $i++)
156 {
157 $total += $_SESSION['panier']['QteArticle'][$i] * $_SESSION['panier']['prixProduit'][$i];
158 }
159 return $total + $total*$_SESSION['panier']['tva']/100;
160 }


Notice: Undefined index: tva in C:\wamp\www\Site e-Commerce\panier.php on line 160

154 for($i = 0; $i<$nbproduits; $i++){
155 ?>
156 <tr>
157 <td></br><?php echo $_SESSION['panier']['titreProduit'][$i]; ?></td>
158 <td></br><?php echo $_SESSION['panier']['prixProduit'][$i]; ?></td>
159<td></br><input name="q[]" value="<?php echo $_SESSION['panier']['QteArticle'][$i] ?>" size="5"/></td>
160<td></br><?php echo $_SESSION['panier']['tva']." %"; ?></td>
161<td></br><a href="panier.php?action=suppression&l=<?php echo
rawurlencode($_SESSION['panier']['titreProduit'][$i]); ?>">X</a></td>
162 </tr>
163 <?php } ?>
164 <tr>

Est Lorsque je vide le panier :

Fatal error: in C:\wamp\www\Site e-Commerce\include\fonctions_panier.php on line 30
( ! ) PDOException: in C:\wamp\www\Site e-Commerce\include\fonctions_panier.php on line 30



24 if(!isset($_SESSION['panier'])){
25 $_SESSION['panier'] = array();
26 $_SESSION['panier']['titreProduit'] = array();
27 $_SESSION['panier']['QteArticle'] = array();
28 $_SESSION['panier']['prixProduit'] = array();
29 $_SESSION['panier']['verrou'] = false;
30 $select = $db->query("SELECT tva FROM produit");
31 $data = $select->fetch(PDO::FETCH_OBJ);
32 $_SESSION['panier']['tva'] = $data->tva;
33 }
34 return true;
35 }

Re: Problème Php : Undifined Index ..

Posté : 01 juil. 2015, 09:47
par tof73
il faut surtout vérifier le code qui initialise $_SESSION['panier']['tva'] lors de l'ajout au panier, et pas seulement lorsqu'il est vidé.

$select = $db->query("SELECT tva FROM produit");
bizarre, que contient la table produit ?

Re: Problème Php : Undifined Index ..

Posté : 01 juil. 2015, 21:26
par Othy
Voila le contenu de la table Produit :

id_produit
titre_produit
des_produit
prix_produit
categorie
Distance
prix_livraison
tva
stock
prix_final

Re: Problème Php : Undifined Index ..

Posté : 01 juil. 2015, 21:30
par Othy
Est voila le code d'ajout d'article :
function ajouterArticle($titreproduit,$QteArticle,$prixproduit){
//Si le panier existe
if(creationPanier() && !isVerouiller()){
//Si le produit existe déjà on ajoute seulement la quantité
$position_produit = array_search($titreproduit,$_SESSION['panier']['titreProduit']);
if($position_produit !== false){
$_SESSION['panier']['QteArticle'][$position_produit] += $QteArticle;
}else{
//Sinon on ajoute le produit
array_push($_SESSION['panier']['titreProduit'],$titreproduit);
array_push($_SESSION['panier']['QteArticle'],$QteArticle);
array_push($_SESSION['panier']['prixProduit'],$prixproduit);
}
}else{
echo 'Erreur .. !! ';
}
}

Re: Problème Php : Undifined Index ..

Posté : 03 juil. 2015, 11:33
par ynx
Salut,

La TVA devrait être enregistrée dans la session lors de l'ajout d'un article dans le panier afin de pouvoir la réutiliser dans tes autres fonctions.

Ce qui me trouble est que tu gères une TVA unique pour tous les produits du panier. Ne devrais-tu pas avoir une TVA par produit (comme le reflète la table produit) afin de gérer les différents taux de TVA (taux réduit, taux intermédiaire, ...) en fonction du produit ?

Bonne journée