Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/06/2016, 00:42
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
Problemas al introducir gastos de envío en paypal

Hola a todos,

Tengo un problema, mi nivel de php es bajo, pero he conseguido que me funcione una tienda online según las exigencias de google shopping, pero cuando tengo que pasar los gastos de envió a paypal lo que ocurre es que si el cliente escoge un producto pues los gastos se introducen bien, pero si escoge dos productos los gastos se duplican el paypal,
Os agradecería que me echeis una mano voy un poco perdido,
Gracias de antemano, 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="icon" type="image/png" href="/images/favicon.png" />
  69.     <link rel="stylesheet" type="text/css" href="./css/estilos2.css">
  70.     <script type="text/javascript" src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
  71.     <script type="text/javascript"  src="./js/scripts.js"></script>
  72.     <style type="text/css">
  73. <!--
  74. .Estilo1 {font-family: Arial, Helvetica, sans-serif}
  75. -->
  76.     </style>
  77. </head>
  78. <body>
  79.     <header>
  80.         <img src="./imagenes/LOGO-DEFINITIU.png" id="logo">
  81.         <a href="./carritodecompras.php" title="ver carrito de compras">
  82.             <img src="./imagenes/carrito.png">
  83.         </a>
  84.     </header>
  85.     <section>
  86.     <?php
  87. ?>
  88. <?php
  89. if (isset($_SESSION['k_username'])) {
  90.     echo '<center><h3>Usuario: '.$_SESSION['k_username']."</h3></center>";
  91.     echo '<p><center><a href="http://www.miweb.com/registro-usuario/logout.php" class="aceptar" style="width:330px"> Cerrar sesión y salir</a></center></p>';
  92. }
  93. ?>
  94.         <?php
  95.             $total=0;
  96.             if(isset($_SESSION['carrito'])){
  97.             $datos=$_SESSION['carrito'];
  98.            
  99.             $total=0;
  100.             for($i=0;$i<count($datos);$i++){
  101.                
  102.     ?>
  103.                 <div class="producto">
  104.                     <center>
  105.                         <img src="./productos/<?php echo $datos[$i]['Imagen'];?>"><br>
  106.                         <span ><?php echo $datos[$i]['Nombre'];?></span><br>
  107.                         <span>Precio: <?php echo $datos[$i]['Precio'];?></span><br>
  108.                         <span class="subtotal">Subtotal:<?php echo $datos[$i]['Cantidad']*$datos[$i]['Precio'];?></span><br>
  109.                     </center>
  110.                 </div>
  111.             <?php
  112.                 $total=($datos[$i]['Cantidad']*$datos[$i]['Precio'])+$total;
  113.             }
  114.  
  115.             if($total > 0) {
  116.             $sumar = 9;
  117.             }
  118.             if($total < 100) {
  119.             $sumar = 9;
  120.             }
  121.             if($total > 100) {
  122.             $sumar = 25;
  123.             }
  124.             if($total > 150) {
  125.             $sumar = 25;
  126.             }
  127.             if($total > 600) {
  128.             $sumar = 35;
  129.             }
  130.             if($total > 1000) {
  131.             $sumar = 65;
  132.             }
  133.             if($total > 3000) {
  134.             $sumar = 120;
  135.             }
  136.             if($total > 5000) {
  137.             $sumar = 160;
  138.             }
  139.             if($total > 6000) {
  140.             $sumar = 200;
  141.             }      
  142.                  
  143.             $total2 = $sumar;
  144.            
  145.             $total3 = $total+$total2;
  146.             echo '<center><h2 id="total">Gastos de transporte: '.$total2.' €</h2></center>';
  147.             echo '<center><h2 id="total">Total: '.$total3.' €</h2></center>';
  148.             if($total!=0){
  149.                 }else{
  150.                 echo '<center><h2>No has añadido ningun producto</h2></center>';
  151.             }
  152.                    
  153.             ?>
  154.                 <form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="formulario">
  155.                     <input type="hidden" name="cmd" value="_cart">
  156.                     <input type="hidden" name="upload" value="1">
  157.                     <input type="hidden" name="business" value="[email protected]">
  158.                     <input type="hidden" name="currency_code" value="EUR">
  159.                    
  160.                     <?php
  161.                         for($i=0;$i<count($datos);$i++){
  162.                     ?>
  163.                         <input type="hidden" name="item_name_<?php echo $i+1;?>" value="<?php echo $datos[$i]['Nombre'];?>">
  164.                         <input type="hidden" name="amount_<?php echo $i+1;?>" value="<?php echo $datos[$i]['Precio'];?>">
  165.                         <input  type="hidden" name="quantity_<?php echo $i+1;?>" value="<?php echo $datos[$i]['Cantidad'];?>">
  166.                         <input type="hidden" name="shipping_<?php echo $i+1;?>" value="<?php echo $total2;?>"> 
  167.                         <?php
  168.                         }
  169.                     ?>
  170.                        
  171.  
  172.                 <center>
  173.                 <input type="submit" value="Pago mediante PayPal" class="aceptar" style="width:330px">
  174.                 </center>
  175.             </form>
  176.             <?php
  177.             }
  178.            
  179.         ?>
  180.        
  181.         <br>
  182.         <center>
  183.         <form action="https://www.miweb.com/carrito2/pago2.php"><input type="submit" value="Pago mediante transferencia" class="aceptar" style="width:330px">
  184.         </form>
  185.         </center>  
  186.     </section>
  187. </body>
  188. </html>