Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/06/2010, 18:12
Avatar de frankjoel86
frankjoel86
 
Fecha de Ingreso: noviembre-2008
Ubicación: Ica
Mensajes: 295
Antigüedad: 15 años, 5 meses
Puntos: 0
Eliminar un item seleccionado en carrito

Saludos gentita de foros del web, dejo el siguiente codigo para que me puedan apoyar en este humilde carrito de compras q stoy haciendo.

catalogo2.php
----------------------
<?php
session_start();
?>
<?php
include("cn.php");
$qry=mysql_query("select * from productos");
while($row=mysql_fetch_array($qry)){
echo "<table border=1>";
echo "<tr>";
echo "<td colspan=3><img src=$row[img]></td>";
echo "</tr><tr>";
echo "<td>$row[descripcion]</td>";
echo "<td>$row[precio]</td>";
echo "<td><a href='agregarcar2.php?producto=$row[codpro]'>Agregar</a></td>";
echo "<tr>";
echo "</table>";
}
?>




agregarcar2.php
--------------------------
<?php
session_start();
$codpro=$_REQUEST[producto];

include("cn.php");
$sql=mysql_query("select *from productos where codpro=$codpro");
while($row=mysql_fetch_array($sql)){
$codpro=$row[codpro];
$costo=$row[precio];
$item=$row[descripcion];
}
//inicia la sesion itemsEnCesta
$itemsEnCesta=$_SESSION['itemsEnCesta'];
$itemsEnCestaCosto=$_SESSION['itemsEnCestaCosto'];

if ($item){ //comprueba si se a agregado un producto
if (!isset($itemsEnCesta)){ //comprueba si se ha iniciado sesion
$itemsEnCesta[$item]=1; //guarda la cantidad en el array ejemplo: $itemsEnCesta[bolso blanco]=20
$itemsEnCestaCosto[$item]=$costo;
}
else{
foreach($itemsEnCesta as $k => $v){
if ($item==$k){
$itemsEnCesta[$k]+=1;
$itemsEnCestaCosto[$k]+=$costo;
$encontrado=1;
}
}
if (!$encontrado) $itemsEnCesta[$item]=$cantidad; $itemsEnCestaCosto[$item]=$costo;
}
}

//actualiza la sesion con los datos agregados
$_SESSION['itemsEnCesta']=$itemsEnCesta;
$_SESSION['itemsEnCestaCosto']=$itemsEnCestaCosto;

?>
<style type="text/css">
<!--
.tit {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
color: #FFFFFF;
}
.prod {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
color: #333333;
}
h1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 20px;
color: #990000;
}
-->
</style>
<?php
if (isset($itemsEnCesta)){
echo'El contenido de la cesta de la compra es:<br><br>';
?>
<table width="720" border="1" cellspacing="0" cellpadding="0" align="center">
<tr bgcolor="#333333" class="tit">
<td width="105">Producto</td>
<td width="207">Precio</td>
<td colspan="2" align="center">Cantidad de Unidades</td>
<td width="100" align="center">Borrar</td>
<td width="159" align="center">Actualizar</td>
</tr>
<?php
foreach($itemsEnCesta as $k => $v){
$valor = $v * $itemsEnCestaCosto[$k];
//echo 'Artículo: '.$k.' cantidad: '.$v.' Costo unitario: '.$itemsEnCestaCosto[$k].' Valor: '.$valor.' <br>';
echo "<tr>
<td>$k</td>
<td>$itemsEnCestaCosto[$k]</td>
<td>$v</td>
<td><input name='cantidad' type='text' value=$v size=8></td>
<td><a href='borracar.php?borrar=$v[id]><input name='imageField' type='image' src='actualizar.gif' width=20 height=20 border=0></a></td>
<td align='center'><input name='imageField' type='image' src='actualizar.gif' width=20 height=20 border=0></td>
</tr>";
$totalArt += $v;
$total += $valor;
}
}
?>
<?php echo '<br>Articulos totales: '.$totalArt.'<br>Costo total: '.$total.''; ?>
<a href='catalogo2.php'>Continuar la selección de productos</a>

#Es lo poco que e podido hacer funciona tranquilo. la pregunta es, como hago para eliminar un $item seleccionado.