Ver Mensaje Individual
  #2 (permalink)  
Antiguo 08/07/2008, 10:21
Avatar de xxrandyxx
xxrandyxx
 
Fecha de Ingreso: abril-2008
Ubicación: En mi casa
Mensajes: 143
Antigüedad: 16 años, 10 meses
Puntos: 2
Respuesta: carrito de compras

Hola la verdad, me pongo a pensar, cuando yo hice la misma pregunta nadie me respondio, igual que a ti, solo por eso estoy que trato de responder las preguntas que se y por eso te mando el codigo ok!!!

Tienes que saber html y Php para que comprendas el codigo, pero yo te lo el mio tu solo cambialo y subelo a tu servidor!

Código PHP:
<? 
session_start
(); 
session_register('itemsEnCesta'); 
if (
$_POST["Producto"]) 
//comprobamos si existe algún Producto 
if (!isset($itemsEnCesta)) { 
$items["Producto"]=$_POST["Producto"]; 
$items["Cantidad"]=$_POST["Cantidad"]; 
$items["Precio"]=$_POST["cuota"]; 
$items["Nombre"]=$_POST["Nombre"]; 
$itemsEnCesta= array($items); } 
else { 
//recorremos su contenido, con foreach, y si encontramos un artículo igual, añadimos la Cantidad... 
foreach($itemsEnCesta as $ind => $item_v) { 
if (
$item_v["Producto"]==$_POST["Producto"]) { 
$itemsEnCesta[$ind]["Cantidad"]+=$_POST["Cantidad"]; 
$encontrado=1; } 
// Si no lo encontramos, es un nuevo artículo, por lo tanto, añadimos el nuevo Producto con la correspondiente Cantidad a compra 
if (!$encontrado) { 
$items["Producto"]=$_POST["Producto"]; 
$items["Cantidad"]=$_POST["Cantidad"]; 
$items["Precio"]=$_POST["cuota"]; 
$items["Nombre"]=$_POST["Nombre"]; 
$itemsEnCesta[]=$items; } 

}
if (isset(
$itemsEnCesta)) { 
foreach(
$itemsEnCesta as $k => $items) { 
$subto=$items["Cantidad"]*$items["Precio"];
$suma=$suma+$subto;
}
}
?>
El primer codigo que te mande crea la sesion del carrito de compras, adquiriento todos los productos y toda esa cosa.

Código PHP:
                      <? 
if (isset($itemsEnCesta)) { 
echo
'<table width="400" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="textblancosinspace">
'
;
foreach(
$itemsEnCesta as $k => $items) { 

if (
$colorfila==0){
       
$color"#F05A00";
       
$colorfila=1;
    }else{
       
$color="#D84F00";
       
$colorfila=0;
    }
    
echo 
'<table bgcolor='.$color.' width="500" border="1" bordercolor="#D84F00" valign="top"  cellspacing="0" cellpadding="0" id="tabla"    onMouseOver="resaltar(this)"
    onMouseOut="normal(this)"
    onClick="marcar(this)" >
        <tr>
          <td width="180" height="20" align="left">'
.$items["Nombre"].'</td>
          <td width="80" height="20" align="center">'
.$items["Producto"].'</td>
          <td width="100" height="20" align="center">S/.'
.number_format($items["Precio"],2).'</td>
          <td width="60" height="20" align="center">'
.$items["Cantidad"].'</td>
          <td width="80" height="20" align="center">S/. '
.number_format ($items["Cantidad"] * $items["Precio"],2).'</td>
          </td>
          </tr>
      </table>
'
;

echo 
"<br></td>
  </tr>
</table>"



else {
echo
' <span class="texto_blanco_black">No Tienes Agregado Ni Un Producto al Carrito de Compras</span> ';

?>
Este segundo codigo es el que muestra lo que esta en tu carrito de compras.

Pero diras ahora como hago con los productos, como los agrego, Pues chapa este codigo bien YUCA!


Código PHP:
<table width="240" height="260" border="0" cellspacing="0" cellpadding="0">
                  <
tr>
                    <
td width="20" height="20">&nbsp;</td>
                    <
td height="20" align="left" valign="top" class="texto_blanco_black2"><input name="Nombre" type="text" class="sinborde" id="Nombre" value="RTD'S" size="15" maxlength="20" /></td>
                    <
td width="20" height="20">&nbsp;</td>
                  </
tr>
                  <
tr>
                    <
td width="20">&nbsp;</td>
                    <
class="test2"><td width="200" height="200" align="center" background="imagenes/fondo.png"><div align="center"><a rel="group1" href="imagenes/productos/imagenes_pequenas_stock/rirtd_po_main[1].jpg" title="RTD'S" target="_blank"><img src="imagenes/productos/imagenes_pequenas_stock/rtds.jpg" alt="RTDS" width="150" height="150" border="0" /></a></div></td></p>
                    <
td width="20">&nbsp;</td>
                  </
tr>
                  <
tr>
                    <
td width="20" height="20">&nbsp;</td>
                    <
td height="20">&nbsp;</td>
                    <
td width="20" height="20">&nbsp;</td>
                  </
tr>
                  <
tr>
                    <
td height="50">&nbsp;</td>
                    <
td height="50" align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <
tr>
                          <
td width="200" align="center" valign="middle" class="texto_blanco_black"><label></label>
                              <
table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <
tr>
                                  <
td width="50%" class="texto_blanco_black">Item:</td>
                                  <
td width="50%"><input name="Producto" type="text" class="sinborde" id="Producto" value="8755" size="7" maxlength="20" /></td>
                                </
tr>
                                <
tr>
                                  <
td width="50%" class="texto_blanco_black">**Precio:</td>
                                  <
td width="50%"><input name="cuota" type="text" class="sinborde" id="cuota" value="99" size="7" maxlength="20" /></td>
                                </
tr>
                            </
table></td>
                          <
td width="75" align="right"><table width="80" border="0" cellspacing="2" cellpadding="0">
                              <
tr>
                                <
td width="75" align="left"><a href="listas_stock/ceramic_infrared_radiators/fsf/menu_fsf.php">
                                  <
label></label>
                                  <
label></label>
                                </
a><a href="listas_stock/ceramic_infrared_radiators/fsf/detalle_fsf4.php?item=119"><img src="imagenes/button_details.gif" alt="Detalles" width="75" height="16" border="0" /></a></td>
                              </
tr>
                          </
table></td>
                        </
tr>
                      </
table>
                        <
table width="100%" border="0" cellspacing="2" cellpadding="0">
                          <
tr>
                            <
td align="center"><span class="textblancosinspace">Cantidad:
                              <
label>
                                  <
input name="Cantidad" type="text" class="text4sinspace2" id="Cantidad" value="1" size="3" maxlength="20" />
                                  </
label>
                              </
span>
                                <
label></label></td>
                          </
tr>
                          <
tr>
                            <
td align="center"><a href="listas_stock/ceramic_infrared_radiators/fsf/menu_fsf.php">
                              <
input name="imageField5" type="image" src="imagenes/button_add_to_cart1.gif" width="122" height="16" border="0" />
                            </
a></td>
                          </
tr>
                      </
table></td>
                    <
td height="50">&nbsp;</td>
                  </
tr>
                </
table
Este codigo es una tabla simple que yo cree, con la imagen de mi producto y unos select que me ayudan a enviar los datos a la sesion creada.


Atento a esto, el codigo que te mande los dos primeros tienen que estar en una web por separado, claro si quieres para que no te confundas.

El tercer codigo metelo en otra web pero no olvides meter en la cabezera de la segunda pagina este codigo


Código PHP:
<? 
session_start
(); 
session_register('itemsEnCesta'); 
if (
$_POST["Producto"]) 
//comprobamos si existe algún Producto 
if (!isset($itemsEnCesta)) { 
$items["Producto"]=$_POST["Producto"]; 
$items["Cantidad"]=$_POST["Cantidad"]; 
$items["Precio"]=$_POST["cuota"]; 
$items["Nombre"]=$_POST["Nombre"]; 
$itemsEnCesta= array($items); } 
else { 
//recorremos su contenido, con foreach, y si encontramos un artículo igual, añadimos la Cantidad... 
foreach($itemsEnCesta as $ind => $item_v) { 
if (
$item_v["Producto"]==$_POST["Producto"]) { 
$itemsEnCesta[$ind]["Cantidad"]+=$_POST["Cantidad"]; 
$encontrado=1; } 
// Si no lo encontramos, es un nuevo artículo, por lo tanto, añadimos el nuevo Producto con la correspondiente Cantidad a compra 
if (!$encontrado) { 
$items["Producto"]=$_POST["Producto"]; 
$items["Cantidad"]=$_POST["Cantidad"]; 
$items["Precio"]=$_POST["cuota"]; 
$items["Nombre"]=$_POST["Nombre"]; 
$itemsEnCesta[]=$items; } 

}
?>
o esto mas facil

Código PHP:
<? 
session_start
(); 
session_register('itemsEnCesta'); ?>
los dos funcionan igual, te doy los dos por si no funciona!


OYE SUERTE Y CON LO QUE APRENDAS RESPONDE A TUS DEMAS COMPAÑEROS QUE NADIE LE HACE CASO COMO ME PASO A MI Y A OTROS MAS COMO TU SUERTE!!!!