Ver Mensaje Individual
  #18 (permalink)  
Antiguo 08/12/2009, 14:57
Avatar de masterojitos
masterojitos
 
Fecha de Ingreso: julio-2008
Ubicación: Lima Callao Chucuito
Mensajes: 1.931
Antigüedad: 15 años, 9 meses
Puntos: 105
Respuesta: Como hacer un carrito de compras sin registro?

ps mira aqui te dejo el codigo de ejemplo....... es la logica de como hacer un carrito con session.

Código php:
Ver original
  1. <?php
  2. $item=$_POST['item'];
  3. $cantidad=$_POST['cantidad'];
  4. $itemsEnCesta=$_SESSION['itemsEnCesta'];
  5.  
  6. if ($item){
  7.     if (!isset($itemsEnCesta)){
  8.         $itemsEnCesta[$item]=$cantidad;
  9.     }else{
  10.         foreach($itemsEnCesta as $k => $v){
  11.             if ($item==$k){
  12.             $itemsEnCesta[$k]+=$cantidad;
  13.             $encontrado=1;
  14.             }
  15.         }
  16.         if (!$encontrado) $itemsEnCesta[$item]=$cantidad;
  17.     }
  18. }
  19. $_SESSION['itemsEnCesta']=$itemsEnCesta;
  20. ?>
  21. <html>
  22. <body>
  23. <form action="" method="post">
  24. Dime el producto <input type="text" name="item" size="20"><br>
  25. Cuantas unidades <input type="text" name="cantidad" size="20"><br>
  26. <input type="submit" value="Añadir a la cesta"><br>
  27. </form>
  28. <?
  29. if (isset($itemsEnCesta)){
  30.     echo'El contenido de la cesta de la compra es:<br>';
  31.     foreach($itemsEnCesta as $k => $v) echo 'Artículo: '.$k.' - Cantidad: '.$v.'<br>';
  32. }
  33. ?>
  34. </body>
  35. </html>

y la vista previa seria asi: http://www.webestilo.com/php/ejem/ejem12e.phtml

Ya solo deberias cambiar algunas cosas para hacer el tuyo.

pero ya tu mismo eres.

Gracias por el karma :P

Suerte.
__________________
Atte. MasterOjitos :ojotes:
Todo sobre Programación Web
Las ultimas tendencias en Efectos y Recursos Web: MasterOjitos Blog