Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/01/2015, 12:46
eslomao
 
Fecha de Ingreso: noviembre-2014
Mensajes: 60
Antigüedad: 9 años, 5 meses
Puntos: 0
sumar datos de carrito de compras,

hola chicos, pues eso ando mirando tutoriales y dandole vueltas a ver como podria aumentar la cantidad del mismo articulo cuando le vuelvan a dar, he mirado muchos carrito pero es que el mio es totalmente distinto, de hecho el mio no tienes la tipica
Código PHP:
Ver original
  1. $sesion=[" carro"];
va con una
Código PHP:
Ver original
  1. $sesion=["MM_IdUsuario"];
, va recogiendod atos desde una pagina q la manda a una de manera oculta y la manda al carrito, por medio de un selec y un insert respectivamente, la manera de sumar seria creo qie igual, desde el carrito mandar datos a otra pagina y que esta lo devuelva ya calculado en caso de que pida dos del mismo, os dejo el codigo del carrito, donde aparece los productos ya elegidos
Código PHP:
Ver original
  1. <?php require_once('Connections/conexionzapatos.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. $editFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_SERVER['QUERY_STRING'])) {
  36.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  37. }
  38.   $insertGoTo = "prueb1234.php";
  39.   if (isset($_SERVER['QUERY_STRING'])) {
  40.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  41.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  42.   }
  43.   header(sprintf("Location: %s", $insertGoTo));
  44. }
  45.  
  46. $varUsuario_DatosCarrito = "0";
  47. if (isset($_SESSION["MM_IdUsuario"])) {
  48.   $varUsuario_DatosCarrito = $_SESSION["MM_IdUsuario"];
  49. }
  50. mysql_select_db($database_conexionzapatos, $conexionzapatos);
  51. $query_DatosCarrito = sprintf("SELECT * FROM tblcarrito WHERE tblcarrito.idUsuario = %s AND tblcarrito.intTransaccionEfectuada = 0", GetSQLValueString($varUsuario_DatosCarrito, "int"));
  52. $DatosCarrito = mysql_query($query_DatosCarrito, $conexionzapatos) or die(mysql_error());
  53. $row_DatosCarrito = mysql_fetch_assoc($DatosCarrito);
  54. $totalRows_DatosCarrito = mysql_num_rows($DatosCarrito);
  55.  
  56. $hoy = date("Y-m-d");
  57. $Transferencia="Transferencia";
  58.  
  59. $multiplicador =  ObtenerIVA()/100;
  60. $valordelIVA = $preciototal * $multiplicador;
  61.  
  62.  
  63. ?>
  64. <?php if ($totalRows_DatosCarrito > 0) { // Show if recordset not empty ?>
  65.        <table width="100%" border="0" cellspacing="0" cellpadding="0">
  66.                   <tr class="ver">
  67.                     <td width="23%">Producto</td>
  68.                     <td width="33%">Unidades</td>
  69.                     <td width="33%">Precio</td>
  70.                     <td width="9%">Acciones</td>
  71.                   </tr>
  72.                   <?php $preciototal = 0;?>
  73.                   <?php do { ?>
  74.   <tr class="letra">
  75.     <td align=""><?php echo ObtenerNombreProducto($row_DatosCarrito['idProducto']); ?></td>
  76.     <td><?php echo $row_DatosCarrito['intCantidad']; ?><a href="sumar_producto.php?idlinea=<?php echo $row_DatosCarrito['intContador']; ?>">+</a>    <?php if ($row_DatosCarrito['intCantidad']!=1){?>
  77.     <a href="restar_producto.php?idlinea=<?php echo $row_DatosCarrito['intContador']; ?>">-</a>    <?php }?></td>
  78.     <td ><?php echo ObtenerPrecioProducto($row_DatosCarrito['idProducto']); ?> <span class="letra">Euros</span></td>
  79.     <td><a href="eliminar_producto.php?recordID=<?php echo $row_DatosCarrito['idProducto']; ?>">Eliminar</a></td>
  80.   </tr>
  81. <?php   $preciototal = $preciototal + ObtenerPrecioProducto($row_DatosCarrito['idProducto']);?>
  82.   <?php } while ($row_DatosCarrito = mysql_fetch_assoc($DatosCarrito)); ?>
  83.         <tr>
  84.     <td>&nbsp;</td>
  85.     <td align="right">Subtotal:</td>
  86.     <td align="left"> <?php
  87.           $multiplicador =  (100 + ObtenerIVA())/100;
  88.           $valorconIVA = $preciototal * $multiplicador;
  89.           echo $valorconIVA;?>
  90.     </td><td>
  91.           <td width="2%">&nbsp;</td>
  92.         </tr>
  93.  </tr>
  94.   </table>  
  95. <table width="433" height="32" align="left">
  96.     <td width="425" align="center">
  97.        <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  98.                       <input type="submit" value="Insertar registro" />
  99.                     </tr>
  100.                  
  101.                   <input type="hidden" name="idCompra" value="" />
  102.                   <input type="hidden" name="idUsuario" value="<?php echo $row_DatosCarrito['idUsuario']; ?>" />
  103.                   <input type="hidden" name="fchFecha" value="<?php echo $hoy ?>" />
  104.                   <input type="hidden" name="intTipoPago" value="<?php echo $Transferencia ?>" />
  105.                   <input type="hidden" name="dblTotal" value="<?php
  106.           $multiplicador =  (100 + ObtenerIVA())/100;
  107.           $valorconIVA = $preciototal * $multiplicador;
  108.           echo $valorconIVA;?>" />
  109.                   <input type="hidden" name="intEstado" value="1" />
  110.                   <input type="hidden" name="strNombre" value=" <?php echo ObtenerNombreUsuario($_SESSION['MM_IdUsuario']) ?>" />
  111.                  
  112.                   <input type="hidden" name="MM_insert" value="form1" />
  113.               </form>
  114.             </table>              
  115.    <?php } // Show if recordset not empty ?>
  116.    <?php if ($totalRows_DatosCarrito == 0) { // Show if recordset empty ?>
  117.   <p>&nbsp;<table width="363" align="center">
  118.     <tr>
  119.       <td width="355" align="center">Su Carro Esta Vacio</td>
  120.       </tr>
  121.   </table>
  122.   <?php } // Show if recordset empty ?>
lo intente con un foreach , pero cuando lo hago me sale error, y pie de pagina, otra cosa seria es como cerrar la sesion del carro cuando se termine la compra, si que ello haga que el usuario tenga que volver a acceder a la pagina, gracias