quantité d'un article qui augment au rafraichissement

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : quantité d'un article qui augment au rafraichissement

Re: quantité d'un article qui augment au rafraichissement

par wwwbillgates » 04 juil. 2010, 18:25

Bien pourquoi tu ne recalcule pas avant de valider.
Visiblement cela doit être un problème de rafraichissement
Effectivement ca serait l'idéal mais je ne sais pas comment faire étant débutant. Car pour recalculer jutilise un input refresh mais comment faire pour l'utiliser sans avoir a cliquer dessus?

Re: quantité d'un article qui augment au rafraichissement

par Aureusms » 04 juil. 2010, 18:01

Bien pourquoi tu ne recalcule pas avant de valider.
Visiblement cela doit être un problème de rafraichissement

quantité d'un article qui augment au rafraichissement

par wwwbillgates » 04 juil. 2010, 16:24

Bonjour à tous, j'ai le panier de ma page http://www.mabouille.com/mabouille/temp ... pports.php qui a un problème car lorsque j'ajoute un article et que je valide le panier alors la quantité double. Je n'arrive pas à trouver d'ou viens le problème mais si je clic sur le bouton recalculer avant de valider mon panier, alors ca fonctionne correctement ? :?

<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
   <head>
       <title>&#8362; Une idée cadeau original pour un anniversaire et des cadeaux Personnalisés de départ à la retraite.</title>
       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	   <meta name="description" content="Idée cadeau original pour homme. La boutique des cadeaux originaux pour femme. Idée cadeaux pour anniversaire, noël, saint valentin, départ en retraite...">
	   <meta name="keywords" content="anniversaire, aniversaire, aniverssaire, idée cadeau, idée cadeaux, idées cadeaux, idee, idée, idées,idee,cadeau, cadeaux, original, cadeau original, originaux, cadeaux originaux, sympathique, caricature, carricature, caricature, insolites, carte personnalisée, perssonalisee, rigolo, pas cher, fun">   
   </head>
   
<body>
<link rel="stylesheet" media="screen" type="text/css" title="CSS" href="../../templates/css/pages.css" />
<link rel="stylesheet" media="screen" type="text/css" title="CSS" href="../../templates/css/etape4.css" />

<!-------------------->
<!---- Menu haut
<!-------------------->   
<!--connexion mysql-->
<?php include("../../class/bouilleDB.php"); ?>
<!--fonctions-->
<?php include("../../includes/functions/functions.php"); ?>











<?php
  /***************************************************/
 /*** Redirection si des sessions sont manquantes
/***************************************************/
if (!isset($_SESSION['prix_de_la_mise_en_situation'], $_SESSION['nom_de_la_mise_en_situation']))
{
	redirige("http://www.mabouille.com/" );
}
?>












<?php	
	  /*************************/
	 /*** Fonctions supports
	/*************************/

	
function creationPanier(){
   if (!isset($_SESSION['supports'])){
      $_SESSION['supports']=array();
      $_SESSION['supports']['libelleProduit'] = array();
      $_SESSION['supports']['qteProduit'] = array();
      $_SESSION['supports']['prixProduit'] = array();
      $_SESSION['supports']['textarea'] = array();	  
      $_SESSION['supports']['verrou'] = false;
   }
   return true;
}








//Ajoute un article dans le panier
function ajouterArticle($libelleProduit,$qteProduit,$prixProduit,$textarea){

   //Si le panier existe
   if (creationPanier() and !isVerrouille())
   {
      //Si le produit existe déjà on ajoute seulement la quantité
      $positionProduit = array_search($libelleProduit,  $_SESSION['supports']['libelleProduit']);

      if ($positionProduit !== false)
      {
         $_SESSION['supports']['qteProduit'][$positionProduit] += $qteProduit ;
      }
      else
      {
         //Sinon on ajoute le produit
         array_push( $_SESSION['supports']['libelleProduit'],$libelleProduit);
         array_push( $_SESSION['supports']['qteProduit'],$qteProduit);
         array_push( $_SESSION['supports']['prixProduit'],$prixProduit);
		 array_push( $_SESSION['supports']['textarea'],$textarea);
      }
   }
   else
   echo "Un problème est survenu veuillez nous contacter.";
}









//Modifie la quantité d'un article
function modifierQTeArticle($libelleProduit,$qteProduit)
{
   //Si le panier éxiste
   if (creationPanier() and !isVerrouille())
   {
      //Si la quantité est positive on modifie sinon on supprime l'article
      if ($qteProduit > 0)
      {
         //Recherche du produit dans le panier
         $positionProduit = array_search($libelleProduit,  $_SESSION['supports']['libelleProduit']);

         if ($positionProduit !== false)
         {
            $_SESSION['supports']['qteProduit'][$positionProduit] = $qteProduit ;
         }
      }
      else
      supprimerArticle($libelleProduit);
   }
   else
   echo "Un problème est survenu veuillez nous contacter.";
}











//Supprime un article du panier
function supprimerArticle($libelleProduit){
   //Si le panier existe
   if (creationPanier() and !isVerrouille())
   {
      //Nous allons passer par un panier temporaire
      $tmp=array();
      $tmp['libelleProduit'] = array();
      $tmp['qteProduit'] = array();
      $tmp['prixProduit'] = array();
	  $tmp['textarea'] = array();
      $tmp['verrou'] = $_SESSION['supports']['verrou'];

      for($i = 0; $i < count($_SESSION['supports']['libelleProduit']); $i++)
      {
         if ($_SESSION['supports']['libelleProduit'][$i] !== $libelleProduit)
         {
            array_push( $tmp['libelleProduit'],$_SESSION['supports']['libelleProduit'][$i]);
            array_push( $tmp['qteProduit'],$_SESSION['supports']['qteProduit'][$i]);
            array_push( $tmp['prixProduit'],$_SESSION['supports']['prixProduit'][$i]);
			array_push( $tmp['textarea'],$_SESSION['supports']['textarea'][$i]);
         }

      }
      //On remplace le panier en session par notre panier temporaire à jour
      $_SESSION['supports'] =  $tmp;
      //On efface notre panier temporaire
      unset($tmp);
   }
   else
   echo "Un problème est survenu veuillez nous contacter.";
}













//Montant total du panier
function MontantSupports()
{
   $total=0;
   for($i = 0; $i < count(@$_SESSION['supports']['libelleProduit']); $i++)
   {
      $total += $_SESSION['supports']['qteProduit'][$i] * $_SESSION['supports']['prixProduit'][$i];
   }
   return $total;
}










//Fonction de suppression du panier
function supprimePanier(){
   unset($_SESSION['supports']);
}










//Permet de savoir si le panier est verrouillé
function isVerrouille(){
   if (isset($_SESSION['supports']) and $_SESSION['supports']['verrou'])
   return true;
   else
   return false;
}









//Compte le nombre d'articles différents dans le panier
function compterArticles()
{
   if (isset($_SESSION['supports']))
   return count($_SESSION['supports']['libelleProduit']);
   else
   return 0;

}























  /**************************************************************/
 /*** Récupération des variable de la page support_categorie
/**************************************************************/
$erreur = false;


$action = (isset($_POST['action'])? $_POST['action']:  (isset($_GET['action'])? $_GET['action']:null )) ;



if($action !== null)
{
   if(!in_array($action,array('ajout', 'suppression', 'refresh')))
   $erreur=true;

	$support_titre = (isset($_POST['support_titre'])? $_POST['support_titre']:  (isset($_GET['support_titre'])? $_GET['support_titre']:null )) ;
	$support_prix = (isset($_SESSION['temp']['support_prix'])? $_SESSION['temp']['support_prix']:  (isset($_GET['support_prix'])? $_GET['support_prix']:null )) ;
	$support_quantite = (isset($_POST['support_quantite'])? $_POST['support_quantite']:  (isset($_GET['support_quantite'])? $_GET['support_quantite']:null )) ;
	$textarea = (isset($_SESSION['temp']['textarea'])? $_SESSION['temp']['textarea']:  (isset($_GET['textarea'])? $_GET['textarea']:null )) ;

   
   

	$textarea = nl2br($textarea);
	
	//Suppression des espaces verticaux
	$support_titre = preg_replace('#\v#', '',$support_titre);
		   
	//On verifie que $prixProduit soit un float
	$support_prix = floatval($support_prix);
   

    
   if (is_array($support_quantite))
   {
      $QteArticle = array();
      $i=0;
      foreach ($support_quantite as $contenu)
	  {
         $QteArticle[$i++] = intval($contenu);
      }
   }
   else
   $support_quantite = intval($support_quantite);
    
}

if (!$erreur)
{
   switch($action)
   {
      Case "ajout":
         ajouterArticle($support_titre,$support_quantite,$support_prix,$textarea);
         break;

      Case "suppression":
         supprimerArticle($support_titre);
         break;

      Case "refresh" :
         for ($i = 0 ; $i < count($QteArticle) ; $i++)
         {
            modifierQTeArticle($_SESSION['supports']['libelleProduit'][$i],round($QteArticle[$i]));
         }
         break;

      Default:
         break;
   }
}

















  /**********************************/
 /*** Calcules des frais de port
/**********************************/
$pays = 'France';



			$reponse = $bdd->prepare("
									SELECT *
									FROM bouille_fraisdeport
									WHERE pays = :pays
									");
			$reponse->execute(array(
									'pays' => $pays
									));
			$fraisdeport = $reponse->fetch(PDO::FETCH_ASSOC);
			


If (isset($fraisdeport['prix_mini_1']))
{
$_SESSION['frais_livraison'] = 0;

	if (MontantSupports() > $fraisdeport['prix_mini_1'] and MontantSupports() <= $fraisdeport['prix_mini_2'])
	{
		$_SESSION['frais_livraison'] = $fraisdeport['tarif_net_1'];
	}
	elseif (MontantSupports() > $fraisdeport['prix_mini_2'] and MontantSupports() <= $fraisdeport['prix_mini_3'])
	{
		$_SESSION['frais_livraison'] = $fraisdeport['tarif_net_2'];
	}
	elseif (MontantSupports() > $fraisdeport['prix_mini_3'] and MontantSupports() <= $fraisdeport['prix_mini_4'])
	{
		$_SESSION['frais_livraison'] = $fraisdeport['tarif_net_3'];
	}
	elseif (MontantSupports() > $fraisdeport['prix_mini_4'] and MontantSupports() <= $fraisdeport['prix_mini_5'])
	{
		$_SESSION['frais_livraison'] = $fraisdeport['tarif_net_4'];
	}
	elseif (MontantSupports() > $fraisdeport['prix_mini_5'])
	{
		$_SESSION['frais_livraison'] = $fraisdeport['tarif_net_5'];
	}
}
?>











<?php
  /***************************************************************************/
 /*** Suppression de la session magazine lorsque l'on clic sur le bouton X
/***************************************************************************/		
if (isset($_POST['supp_magazine']))
{
	unset($_SESSION['magazine']['oui_non']);
}
?>














 <?php
  /**************************/
 /*** Variable TOTAL TTC
/**************************/
$_SESSION['prix_total'] = MontantSupports() + $_SESSION['prix_de_la_mise_en_situation'] + $_SESSION['magazine']['prix'] + $_SESSION['frais_livraison'] . ' €';













  /********************/
 /*** menu du haut
/********************/
include("../../templates/pages/menu_haut.php");
?>














<!---- page blanche début ---->
<div id="page_blanche">





<!---- Frise ---->
<p >
<img src="../../interface/frise_1.gif" />
<img src="../../interface/frise_2.gif" />
<img src="../../interface/frise_3.gif" />
<img src="../../interface/frise_4.gif" />
<img src="../../interface/frise_5off.gif" />
<img src="../../interface/frise_6off.gif" />
<img src="../../interface/frise_7off.gif" />
</p>



<br />



<!---- Introduction ---->
<p>
Pour continuer votre commande, nous vous invitons à choisir une catégorie pour ajouter vos supports.
</p>













<?php
  /***********************************************/
 /*** Redirection vers étape d'identification
/***********************************************/
if(isset($_POST['valider']) == 1)
{
	$erreur_objet_manquant = array();

	
	
	//Erreur support absent
		if (empty($_SESSION['supports']['libelleProduit']))
		{
			?><script language="javascript"> alert("Vous devez ajouter au moins 1 support dans votre panier \n (des supports numériques gratuits sont disponibles)"); </script><?php
			$erreur_objet_manquant[0] = "Vous devez ajouter au moins 1 support dans votre panier (des supports numériques gratuits sont disponibles)";
		}

		
		
		if (empty($erreur_objet_manquant))
		{
			//Destruction des variables temp
			unset($_SESSION['temp']);
			
			$_SESSION['supports']['verrou'] = false;
			
			//Redirection
			redirige("../../templates/pages/etape5_identification.php" );
		}
					
}	
?>















<?php
  /*********************************************************/
 /*** Affichage du tableau d'erreur pour la redirection
/*********************************************************/
echo '<div class="tableau_derreur" >';
	if (isset ($erreur_objet_manquant))
	{
		if( count( $erreur_objet_manquant ) !== 0 )
		{
			echo( "\t\t<ul>\n" );
			foreach( $erreur_objet_manquant as $error )
			{
				echo( "\t\t\t<li>$error</li>\n" );
			}
			echo( "\t\t</ul>\n" );
		}
	}
echo '</div>';
?>











<!---------------------------->
<!---- Catégorie supports
<!---------------------------->	
<div class="categories" >
<p>
	<a href="../../templates/pages/etape4_supports_categorie.php?categorie=1"><img src="../../interface/categorie_papeterie.jpg" alt="Catégorie papeterie et cadres." /></a>
	<a href="../../templates/pages/etape4_supports_categorie.php?categorie=1">PAPETERIE, CADRES</a>
</p>

<p>
	<a href="../../templates/pages/etape4_supports_categorie.php?categorie=2"><img src="../../interface/categorie_deco.jpg" alt="Catégorie pour la maison et la déco." /></a>
	<a href="../../templates/pages/etape4_supports_categorie.php?categorie=2">MAISON, DECO</a>
</p>

<p>
	<a href="../../templates/pages/etape4_supports_categorie.php?categorie=3"><img src="../../interface/categorie_cuisine.jpg" alt="Catégorie pour la cuisine, vaisselle..." /></a>
	<a href="../../templates/pages/etape4_supports_categorie.php?categorie=3">VAISSELLE, CUISINE</a>
</p>

<p>
	<a href="../../templates/pages/etape4_supports_categorie.php?categorie=4"><img src="../../interface/categorie_vetements.jpg" alt="Catégorie tee-shirts, vêtements..." /></a>
	<a href="../../templates/pages/etape4_supports_categorie.php?categorie=4">T-SHIRTS, VETEMENTS</a>
</p>

<p>
	<a href="../../templates/pages/etape4_supports_categorie.php?categorie=5"><img src="../../interface/categorie_jeux.jpg" alt="Catégorie jeux, jouets..." /></a>
	<a href="../../templates/pages/etape4_supports_categorie.php?categorie=5">JEUX, JOUETS</a>
</p>

<p>
	<a href="../../templates/pages/etape4_supports_categorie.php?categorie=6"><img src="../../interface/categorie_bureau.jpg" alt="Catégorie bureautique, accessoires, numériques..." /></a>
	<a href="../../templates/pages/etape4_supports_categorie.php?categorie=6">BUREAU, ACCESSOIRES,<br />NUMERIQUE (GRATUITS)</a>
</p>
</div>












<!-------------------------------------------->
<!---- Panier (modifier aussi panier.php)
<!-------------------------------------------->
<div id="tableau" >
			<form method="post" action="#">
			<table>
			<tr>
				<th class="titre" width="50px" >supp.</th>
				<th class="titre" width="400px" >Articles</th>
				<th class="titre" width="135px" >Prix unitaire</th>
				<th class="titre" width="135px" >Quantité</th>
				<th class="titre" width="135px" >Montant TTC</th>
			<tr>
		  	</tr>
				<td><a href="http://www.mabouille.com/" onmouseover="supp_miseensituation.src = '../../interface/bt_supprimer_push.gif';" onmouseout="supp_miseensituation.src = '../../interface/bt_supprimer.gif';"><img src="../../interface/bt_supprimer.gif" name="supp_miseensituation" ></a></td>
				<td class="article" ><?php echo 'Réalisation : '. $_SESSION['nom_de_la_mise_en_situation'] . ' pour ' . $_SESSION['quantite_de_bouilles'] . ' bouille' . pluriel($_SESSION['quantite_de_bouilles']) . '.'; ?></td>
				<td class="article" ><?php echo $_SESSION['prix_de_la_mise_en_situation'] . ' €' ?></td>
				<td class="article" >1</td>
				<td class="article" ><?php echo $_SESSION['prix_de_la_mise_en_situation'] . ' €' ?></td>
			</tr>		  	
		

		
		
		
		
		
		
		<?php
		  /****************************************/
		 /*** Afficher la description magazine
		/****************************************/
		if	(@$_SESSION['magazine']['oui_non'] == 1)
		{
			?>
			</tr>
				<td><input type="image" value="supp_magazine" name="supp_magazine" src="../../interface/bt_supprimer.gif" onmouseover="this.src='../../interface/bt_supprimer_push.gif'" onmouseout="this.src='../../interface/bt_supprimer.gif'" /></td>
				<td class="article" ><?php echo 'Présentation comme une 1ère de couv\' :<br /> <span class="presentation" ><strong>date :</strong> ' . $_SESSION['magazine']['date'] . '<br /> <strong>titre :</strong> ' . $_SESSION['magazine']['titre'] . '<br /> <strong>texte1 :</strong> ' . $_SESSION['magazine']['texte1'] . '<br /> <strong>texte2 :</strong> ' . $_SESSION['magazine']['texte2'] . '</span>'; ?></td>
				<td class="article" ><?php echo $_SESSION['magazine']['prix'] . ' €' ?></td>
				<td class="article" >1</td>
				<td class="article" ><?php echo $_SESSION['magazine']['prix'] . ' €' ?></td>
			</tr>
			<?php
		}
		?>
			
			
			
			
			
			
			
			
			
			
	<?php
	if (creationPanier())
	{
	   $nbArticles=count($_SESSION['supports']['libelleProduit']);
	   if ($nbArticles <= 0)
	   {	
			?>
			</tr>
				<td></td>
				<td>Vous devez ajouter au moins 1 support dans votre panier.</td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
			<?php
	   }
	   else
	   {
	      for ($i=0 ;$i < $nbArticles ; $i++)
	      {
			?>
			</tr>
				<td><a href="<?php echo htmlspecialchars("../../templates/pages/etape4_supports.php?action=suppression&support_titre=".rawurlencode($_SESSION['supports']['libelleProduit'][$i])); ?>" onmouseover="choisirfond.src = '../../interface/bt_supprimer_push.gif';" onmouseout="choisirfond.src = '../../interface/bt_supprimer.gif';"><img src="../../interface/bt_supprimer.gif" name="choisirfond" ></a></td>
				<td class="article" ><?php echo htmlspecialchars($_SESSION['supports']['libelleProduit'][$i]); if (!empty($_SESSION['supports']['textarea'][$i])) { echo '<br /> <span class="presentation" ><strong>textes :<br /></strong>'; } echo $_SESSION['supports']['textarea'][$i] . '</span>'; ?></td>
				<td class="article" ><?php echo htmlspecialchars($_SESSION['supports']['prixProduit'][$i]) . ' €' ?></td>
				<td class="article" ><?php echo "<input type=\"text\" size=\"4\" name=\"support_quantite[]\" value=\"".htmlspecialchars($_SESSION['supports']['qteProduit'][$i])."\"/>"; ?></td>
				<td class="article" ><?php echo htmlspecialchars($_SESSION['supports']['prixProduit'][$i]) * htmlspecialchars($_SESSION['supports']['qteProduit'][$i]) . ' €' ?></td>
			</tr>
			<?php
	      }
			?>
			</tr>
				<th></th>
				<th></th>
				<th></th>
				<th class="titre" >Montant TTC</th>
				<th class="titre" ><?php echo $_SESSION['prix_total'] - $_SESSION['frais_livraison'] . ' €'; ?></th>
			</tr>
			
			</tr>
				<td></td>
				<td class="minitexte_panier" >*Frais de livraison offert à partir de 100€ du total en supports</td>
				<th></th>
				<th class="titre" >Frais de livraison*</th>
				<th class="titre" ><?php echo $_SESSION['frais_livraison'] . ' €' ?></th>
			</tr>
			
			</tr>
				<th></th>
				<th></th>
				<th></th>
				<th class="titre" >TOTAL TTC</th>
				<th class="titre" ><?php echo $_SESSION['prix_total']; ?></th>
			</tr>
			</table>
			
			
			
			<!---Bouton recalculer--->
			<input class="recalculer" type="image" value="refresh" src="../../interface/bt_recalculer.gif" onmouseover="this.src='../../interface/bt_recalculer_push.gif'" onmouseout="this.src='../../interface/bt_recalculer.gif'">
			<input type="hidden" name="action" value="refresh"/>
			<?php
	   }
	}
?>





<br />


<form method="post" action="#">
	<label for="cheque">Si vous disposez d'un chèque cadeau saisissez le code ici :</label> <input type="text" name="cheque" id="cheque" />
</form>




<p class="minitexte_panier" >
	Dans le cas ou le montant de la commande serait inférieur à la valeur du bon cadeau,<br />
	aucun remboursement ne pourra être effectué. Les bons cadeaux sont non cumulables.
</p>



<form action="#" method="post" >
<p class="boutons_valider" >
	<!--- <a href="../../index.php" onmouseover="continuer.src = '../../interface/bt_continuachat_push.gif';" onmouseout="continuer.src = '../../interface/bt_continuachat.gif';"><img src="../../interface/bt_continuachat.gif" name="continuer" ></a> --->
	<input type="image" name="1" value="1" onclick="document.getElementById('id').value=this.name" src="../../interface/bt_validerpanier.gif" onmouseover="this.src='../../interface/bt_validerpanier_push.gif'" onmouseout="this.src='../../interface/bt_validerpanier.gif'" />
	<input type="hidden" name="valider" id="id" value="" />
</p>
</form>


</div>



















</div>
<!---- page blanche fin ---->





<!---- copyright ---->
<br />
<?php include("copyright.php"); ?>
 
 
</body>
</html>