Ver Mensaje Individual
  #9 (permalink)  
Antiguo 03/04/2008, 19:57
Avatar de sette15
sette15
 
Fecha de Ingreso: noviembre-2007
Ubicación: Rosario, Argentina
Mensajes: 97
Antigüedad: 16 años, 6 meses
Puntos: 0
Re: Comercio Electrónico!

Hola de nuevo, pude encontrar esto que más o menos es parecido a lo que estaba buscando, pero tengo que modificarle un par de cosas y necesito su ayuda. De paso el que lo necesita puede copiar el codigo ...

Este carrito se compone de los siguientes archivos:
Base de datos:
Cita:
create table catalogo (id int not null auto_increment primary key,producto varchar(100),precio decimal(9,2))
agregacar.php
Cita:
<?php
session_start();
extract($_REQUEST);
mysql_connect("localhost","usuario","password");
mysql_select_db("db");
if(!isset($cantidad)){$cantidad=1;}
$qry=mysql_query("select * from catalogo where
id='".$id."'");
$row=mysql_fetch_array($qry);
if(isset($_SESSION['carro']))
$carro=$_SESSION['carro'];
$carro[md5($id)]=array('identificador'=>md5($id),
'cantidad'=>$cantidad,'producto'=>$row['producto'],
'precio'=>$row['precio'],'id'=>$id);
$_SESSION['carro']=$carro;
header("Location:catalogo.php?".SID);
?>
borracar.php
Cita:
<?php
session_start();
extract($_GET);
$carro=$_SESSION['carro'];
$_SESSION['carro']=$carro;
header("Location:catalogo.php?".SID);
?>
catalogo.php
Cita:
<?php
ob_start("ob_gzhandler");
session_start();
mysql_connect("localhost","usuario","password");
mysql_select_db("db");
if(isset($_SESSION['carro']))
$carro=$_SESSION['carro'];else $carro=false;
$qry=mysql_query("select * from catalogo order by producto asc");
?>
<html>
<head>
<title>CATÁLOGO</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.catalogo {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
color: #333333;
}
-->
</style>
</head>
<body>
<table width="272" align="center" cellpadding="0" cellspacing="0" style="border: 1px solid #000000;">
<tr valign="middle" bordercolor="#FFFFFF" bgcolor="#DFDFDF" class="catalogo">
<td width="170"><strong>Producto</strong></td>
<td width="77"><strong>Precio</strong></td>
<td width="25" align="right"><a href="vercarrito.php?<?php echo SID ?>" title="Ver el contenido del carrito">
<img src="vercarrito.gif" width="25" height="21" border="0"></a></td>
</tr>
<?php
while($row=mysql_fetch_assoc($qry)){
?>
<tr valign="middle" class="catalogo">
<td><?php echo $row['producto'] ?></td>
<td><?php echo $row['precio'] ?></td>
<td align="center">
<?php
if(!$carro || !isset($carro[md5($row['id'])]['identificador']) || $carro[md5($row['id'])]['identificador']!=md5($row['id'])){
?>
<a href="agregacar.php?<?php echo SID ?>&id=<?php echo $row['id']; ?>">
<img src="productonoagregado.gif" border="0" title="Agregar al Carrito"></a><?php }else
{?><a href="borracar.php?<?php echo SID ?>&id=<?php echo $row['id']; ?>">
<img src="productoagregado.gif" border="0" title="Quitar del Carrito"></a><?php } ?></td>
</tr><?php } ?>
</table>
</body>
</html>
<?php
ob_end_flush();
?>
varcarrito.php
Cita:
<?php
session_start();
if(isset($_SESSION['carro']))
$carro=$_SESSION['carro'];else $carro=false;
?>
<html>
<head>
<title>PRODUCTOS AGREGADOS AL CARRITO</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<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>
</head>
<body>
<h1 align="center">Carrito</h1>
<?php
if($carro){
?>
<table width="720" border="0" 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
$color=array("#ffffff","#F0F0F0");
$contador=0;
$suma=0;
foreach($carro as $k => $v){
$subto=$v['cantidad']*$v['precio'];
$suma=$suma+$subto;
$contador++;
?>
<form name="a<?php echo $v['identificador'] ?>" method="post" action="agregacar.php?<?php echo SID ?>" id="a<?php echo $v['identificador'] ?>">
<tr bgcolor="<?php echo $color[$contador%2]; ?>" class='prod'>
<td><?php echo $v['producto'] ?></td>
<td><?php echo $v['precio'] ?></td>
<td width="43" align="center"><?php echo $v['cantidad'] ?></td>
<td width="136" align="center">
<input name="cantidad" type="text" id="cantidad" value="<?php echo $v['cantidad'] ?>" size="8">
<input name="id" type="hidden" id="id" value="<?php echo $v['id'] ?>"> </td>
<td align="center"><a href="borracar.php?<?php echo SID ?>&id=<?php echo $v['id'] ?>"><img src="trash.gif" width="12" height="14" border="0"></a></td>
<td align="center">
<input name="imageField" type="image" src="actualizar.gif" width="20" height="20" border="0"></td>
</tr></form>
<?php
}
?>
</table>
<div align="center"><span class="prod">Total de Artículos: <?php echo count($carro);
?></span>
</div><br>
<div align="center"><span class="prod">Total: $<?php echo number_format($suma,2);
?></span>
</div><br>
<div align="center"><span class="prod">Continuar la selección de productos</span>
<a href="catalogo.php?<?php echo SID;?>">
<img src="continuar.gif" width="13" height="13" border="0"></a>
</div>
<?php }else{ ?>
<p align="center"> <span class="prod">No hay productos seleccionados</span>
<a href="catalogo.php?<?php echo SID;?>">
<img src="continuar.gif" width="13" height="13" border="0"></a>
<?php }?>
</p>
</body>
</html>
Lo que yo ise fue sacar "catalogo.php" y hacer un formulario nuevo que con un texbox "cantidad" y un botón "Agregar" que luego el "action" del formulario se dirige a "agregacar.php" bueno esto funciona, pero el problema es que al agregar el producto, cuando me dirijo a "vercarrito.php" figura como que hay un producto en la cantidad que yo puse en el texbox "cantidad" del formulario pero no figura el nombre ni el precio del producto.

¿Como puedo hacer para que al agregar el producto figure su nombre y su precio?
¿Tengo que agregar estos datos en la base de datos "catalogo"?
¿Que deveria cambiar despues en el formulario para que sepa a que producto se refiere? Yo estaba pensando que había que cambiar el ID de cada formulario de cada producto para que después la base de datos lo identifique pero no se, ¿que dicen ustedes?

Muchas gracias....

Última edición por sette15; 12/04/2008 a las 13:36