añadir o eliminar productos carro de compras

Iniciado por toyeslomao, 17 Enero 2015, 17:53 PM

0 Miembros y 1 Visitante están viendo este tema.

toyeslomao

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) [Seleccionar]
$sesion=[" carro"]; , esta va con una
Código (php) [Seleccionar]
$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) [Seleccionar]
<?php require_once('Connections/conexionzapatos.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (
PHP_VERSION < 6) {
    
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
 
  
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}
 
$editFormAction = $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
  
$insertGoTo = "prueb1234.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s", $insertGoTo));
}
 
$varUsuario_DatosCarrito = "0";
if (isset(
$_SESSION["MM_IdUsuario"])) {
  
$varUsuario_DatosCarrito = $_SESSION["MM_IdUsuario"];
}
mysql_select_db($database_conexionzapatos, $conexionzapatos);
$query_DatosCarrito = sprintf("SELECT * FROM tblcarrito WHERE tblcarrito.idUsuario = %s AND tblcarrito.intTransaccionEfectuada = 0", GetSQLValueString($varUsuario_DatosCarrito, "int"));
$DatosCarrito = mysql_query($query_DatosCarrito, $conexionzapatos) or die(mysql_error());
$row_DatosCarrito = mysql_fetch_assoc($DatosCarrito);
$totalRows_DatosCarrito = mysql_num_rows($DatosCarrito);
 
$hoy = date("Y-m-d");
$Transferencia="Transferencia";
 
$multiplicador =  ObtenerIVA()/100;
$valordelIVA = $preciototal * $multiplicador;
 
 
?>

<?php if ($totalRows_DatosCarrito > 0) { // Show if recordset not empty ?>
       <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr class="ver">
                    <td width="23%">Producto</td>
                    <td width="33%">Unidades</td>
                    <td width="33%">Precio</td>
                    <td width="9%">Acciones</td>
                  </tr>
                  <?php $preciototal = 0;?>
                  <?php do { ?>
  <tr class="letra">
    <td align=""><?php echo ObtenerNombreProducto($row_DatosCarrito['idProducto']); ?></td>
    <td><?php echo $row_DatosCarrito['intCantidad']; ?><a href="sumar_producto.php?idlinea=<?php echo $row_DatosCarrito['intContador']; ?>">+</a>    <?php if ($row_DatosCarrito['intCantidad']!=1){?>
    <a href="restar_producto.php?idlinea=<?php echo $row_DatosCarrito['intContador']; ?>">-</a>    <?php }?></td>
    <td ><?php echo ObtenerPrecioProducto($row_DatosCarrito['idProducto']); ?> <span class="letra">Euros</span></td>
    <td><a href="eliminar_producto.php?recordID=<?php echo $row_DatosCarrito['idProducto']; ?>">Eliminar</a></td>
  </tr>
<?php   $preciototal = $preciototal + ObtenerPrecioProducto($row_DatosCarrito['idProducto']);?>
  <?php } while ($row_DatosCarrito = mysql_fetch_assoc($DatosCarrito)); ?>
        <tr>
    <td>&nbsp;</td>
    <td align="right">Subtotal:</td>
    <td align="left"> <?php 
          $multiplicador 
=  (100 + ObtenerIVA())/100;
          
$valorconIVA = $preciototal * $multiplicador;
          echo 
$valorconIVA;?>

    </td><td>
          <td width="2%">&nbsp;</td>
        </tr>
</tr>
  </table> 
<table width="433" height="32" align="left">
    <td width="425" align="center">
       <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
                      <input type="submit" value="Insertar registro" />
                    </tr>
                 
                  <input type="hidden" name="idCompra" value="" />
                  <input type="hidden" name="idUsuario" value="<?php echo $row_DatosCarrito['idUsuario']; ?>" />
                  <input type="hidden" name="fchFecha" value="<?php echo $hoy ?>" />
                  <input type="hidden" name="intTipoPago" value="<?php echo $Transferencia ?>" />
                  <input type="hidden" name="dblTotal" value="<?php 
          $multiplicador 
=  (100 + ObtenerIVA())/100;
          
$valorconIVA = $preciototal * $multiplicador;
          echo 
$valorconIVA;?>
" />
                  <input type="hidden" name="intEstado" value="1" />
                  <input type="hidden" name="strNombre" value=" <?php echo ObtenerNombreUsuario($_SESSION['MM_IdUsuario']) ?>" />
                 
                  <input type="hidden" name="MM_insert" value="form1" />
              </form>
            </table>               
   <?php } // Show if recordset not empty ?>
   <?php if ($totalRows_DatosCarrito == 0) { // Show if recordset empty ?>
  <p>&nbsp;<table width="363" align="center">
    <tr>
      <td width="355" align="center">Su Carro Esta Vacio</td>
      </tr>
  </table>
  <?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