Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/09/2014, 10:37
Avatar de jors_11
jors_11
 
Fecha de Ingreso: marzo-2011
Ubicación: Granollers
Mensajes: 79
Antigüedad: 13 años, 1 mes
Puntos: 2
finalizando carrito de compras

Hola Compys!
Estoy finalizando un carrito de compras y me da un error que no consigo solucionar, el tema es que busque la manera de calcular el transporte según el total de la compra, como se puede ver en el código de la pagina "pago.php" y parece que funciona bien, el problema es cuando le doy al botón de pago por Paypal, en la bandeja de entrada de paypal, algunas veces refleja el número correcto y hay otras veces que aparece el doble de lo que debería ser, es decir que si hago una compra que no supere los 100 euros, en la página "pago.php" aparece gastos de transporte 30€ y en Paypal en algunas ocasiones me sale 60€ de gastos de envío.
Estoy casi seguro que no he puesto bien el input type correspondiente a shipping_
Os agradecería si le pudieseis echar un vistazo a esta pagina en general para ver si veis algún error o mejora por hacer.
Saludos,

Código PHP:
Ver original
  1. <?php
  2.     session_start();
  3.     include 'conexion.php';
  4.     if(isset($_SESSION['carrito'])){
  5.         if(isset($_GET['id'])){
  6.                     $arreglo=$_SESSION['carrito'];
  7.                     $encontro=false;
  8.                     $numero=0;
  9.                     for($i=0;$i<count($arreglo);$i++){
  10.                         if($arreglo[$i]['Id']==$_GET['id']){
  11.                             $encontro=true;
  12.                             $numero=$i;
  13.                         }
  14.                     }
  15.                     if($encontro==true){
  16.                         $arreglo[$numero]['Cantidad']=$arreglo[$numero]['Cantidad']+1;
  17.                         $_SESSION['carrito']=$arreglo;
  18.                     }else{
  19.                         $nombre="";
  20.                         $precio=0;
  21.                         $imagen="";
  22.                         $re=mysql_query("select * from productos where id=".$_GET['id']);
  23.                         while ($f=mysql_fetch_array($re)) {
  24.                             $nombre=$f['nombre'];
  25.                             $precio=$f['precio'];
  26.                             $imagen=$f['imagen'];
  27.                         }
  28.                         $datosNuevos=array('Id'=>$_GET['id'],
  29.                                         'Nombre'=>$nombre,
  30.                                         'Precio'=>$precio,
  31.                                         'Imagen'=>$imagen,
  32.                                         'Cantidad'=>1);
  33.  
  34.                         array_push($arreglo, $datosNuevos);
  35.                         $_SESSION['carrito']=$arreglo;
  36.  
  37.                     }
  38.         }
  39.  
  40.  
  41.  
  42.  
  43.     }else{
  44.         if(isset($_GET['id'])){
  45.             $nombre="";
  46.             $precio=0;
  47.             $imagen="";
  48.             $re=mysql_query("select * from productos where id=".$_GET['id']);
  49.             while ($f=mysql_fetch_array($re)) {
  50.                 $nombre=$f['nombre'];
  51.                 $precio=$f['precio'];
  52.                 $imagen=$f['imagen'];
  53.             }
  54.             $arreglo[]=array('Id'=>$_GET['id'],
  55.                             'Nombre'=>$nombre,
  56.                             'Precio'=>$precio,
  57.                             'Imagen'=>$imagen,
  58.                             'Cantidad'=>1);
  59.             $_SESSION['carrito']=$arreglo;
  60.         }
  61.     }
  62. ?>
  63. <!DOCTYPE html>
  64. <html lang="es">
  65. <head>
  66.     <meta charset="utf-8"/>
  67.     <title>Carrito de Compras</title>
  68.     <link rel="stylesheet" type="text/css" href="./css/estilos2.css">
  69.     <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
  70.     <script type="text/javascript"  src="./js/scripts.js"></script>
  71.     <script type="text/JavaScript">
  72. <!--
  73. function MM_swapImgRestore() { //v3.0
  74.   var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  75. }
  76.  
  77. function MM_preloadImages() { //v3.0
  78.   var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  79.     var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  80.     if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  81. }
  82.  
  83. function MM_findObj(n, d) { //v4.01
  84.   var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  85.     d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  86.   if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  87.   for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  88.   if(!x && d.getElementById) x=d.getElementById(n); return x;
  89. }
  90.  
  91. function MM_swapImage() { //v3.0
  92.   var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  93.    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  94. }
  95. //-->
  96. </script>
  97. </head>
  98. <body onLoad="MM_preloadImages('imagenes/boton-transferencia2.png')">
  99.     <header>
  100.         <div align="center"><img src="http://www.pagina.com/carrito/imagenes/LOGO_DEFINITIU.png" id="logo">
  101.           <img src="./imagenes/carrito.png" width="968" height="606">
  102.             </a>          </div>
  103.     </header>
  104.     <section>
  105.  
  106.       <div align="left">
  107.         <?php
  108.             $total=0;
  109.             if(isset($_SESSION['carrito'])){
  110.             $datos=$_SESSION['carrito'];
  111.            
  112.             $total=0;
  113.             for($i=0;$i<count($datos);$i++){
  114.                
  115.     ?>
  116.         </div>
  117.           <div class="producto">
  118.           <center>
  119.             <img src="http://www.pagina.com/carrito/productos/<?php echo $datos[$i]['Imagen'];?>"><br>
  120.               <span ><?php echo $datos[$i]['Nombre'];?></span><br>
  121.               <span>Precio: <?php echo $datos[$i]['Precio'];?></span><br>
  122.               <span class="subtotal">Subtotal: <?php echo $datos[$i]['Cantidad']*$datos[$i]['Precio'];?></span><br>
  123.               </center>
  124.         </div>
  125.             <?php
  126.                 $total=($datos[$i]['Cantidad']*$datos[$i]['Precio'])+$total;
  127.             }
  128.                
  129.             }else{
  130.                 echo '<center><h2>No has selecionado ningún producto</h2></center>';
  131.             }
  132.             echo '<center><h2 id="total">Total Importe: '.$total.' Euros (IVA  </h2></center>';
  133.             if($total!=0){
  134.             ?>
  135.          <?php
  136.            
  137.             if($total < 100) {
  138.             $sumar = 30;
  139.             }
  140.             if($total > 150) {
  141.             $sumar = 40;
  142.             }
  143.             if($total > 600) {
  144.             $sumar = 80;
  145.             }
  146.             if($total > 1000) {
  147.             $sumar = 160;
  148.             }
  149.             if($total > 3000) {
  150.             $sumar = 200;
  151.             }
  152.             if($total > 5000) {
  153.             $sumar = 300;
  154.             }
  155.             if($total > 6000) {
  156.             $sumar = 350;
  157.             }      
  158.            
  159.             $total2 = $sumar;
  160.            
  161.             echo '<center><h2 id="total">Gastos de transporte: '.$total2.' Euros </h2></center>';
  162.             ?>
  163.       </div>
  164.           <p align="center"><a href="http://www.pagina.com/carrito/pago2.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image5','','imagenes/boton-transferencia2.png',1)"><img src="imagenes/boton-transferencia.png" name="Image5" width="260" height="35" border="0"></a><img src="imagenes/transferencia-bancaria.jpg" alt="transferencia" width="121" height="46"></p>
  165.         <form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="formulario">
  166.           <div align="center">
  167.             <p>
  168.               <input type="hidden" name="cmd" value="_cart">
  169.               <input type="hidden" name="upload" value="1">
  170.               <input type="hidden" name="business" value="[email protected]">
  171.               <input type="hidden" name="currency_code" value="EUR">
  172.              
  173.               <?php
  174.                         for($i=0;$i<count($datos);$i++){
  175.                     ?>
  176.               <input type="hidden" name="item_name_<?php echo $i+1;?>" value="<?php echo $datos[$i]['Nombre'];?>">
  177.               <input type="hidden" name="amount_<?php echo $i+1;?>" value="<?php echo $datos[$i]['Precio'];?>">
  178.               <input type="hidden" name="quantity_<?php echo $i+1;?>" value="<?php echo $datos[$i]['Cantidad'];?>">
  179.               <input type="hidden" name="shipping_<?php echo $i+1;?>" value="<?php echo $total2;?>">    
  180.               <?php
  181.                         }
  182.                     ?>
  183.             </p>
  184.               <p>
  185.                
  186.                 <input type="submit" value="PAGO POR PAYPAL" class="aceptar" style="width:250px">
  187.                 <img src="imagenes/paypal.jpg" alt="Paypal" width="124" height="44"></p>
  188.           </div>
  189.         </form>
  190.                   <div align="center">
  191.                     <?php
  192.             }
  193.            
  194.         ?>
  195.         <?php
  196.         header('refresh:500; url=http://www.pagina.com/carrito/cerrar2.php');
  197.         ?>
  198.       </div>
  199. </section>
  200.     <div align="center"></div>
  201. </body>
  202. </html>