PHP - añador y eliminar productos carrito de compras

 
Vista:
sin imagen de perfil

añador y eliminar productos carrito de compras

Publicado por toyeslomao (1 intervención) el 17/01/2015 18:03:36
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
1
$sesion=[" carro"];
, va con
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?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
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder