Foros del Web » Programando para Internet » PHP »

Carrito de compras simple en PHP problem!

Estas en el tema de Carrito de compras simple en PHP problem! en el foro de PHP en Foros del Web. Código PHP: <?php session_start ();  session_register ( 'itemsEnCesta' ); ?> <head> <link href="estilo.css" rel="stylesheet" type="text/css" /> </head> <?php $item = $_POST [ 'item' ];  $talle = $_POST [ 'talle' ...
  #1 (permalink)  
Antiguo 10/06/2010, 16:42
 
Fecha de Ingreso: diciembre-2005
Mensajes: 50
Antigüedad: 18 años, 4 meses
Puntos: 0
Carrito de compras simple en PHP problem!

Código PHP:
<?php
session_start
(); 
session_register('itemsEnCesta');
?><head>
<link href="estilo.css" rel="stylesheet" type="text/css" />
</head>
<?php
$item
=$_POST['item']; 
$talle=$_POST['talle']; 
$color=$_POST['color']; 
$cantidad=$_POST['cantidad']; 
$itemsEnCestaCant=$_SESSION['itemsEnCestaCant']; 
$itemsEnCestaTalle=$_SESSION['itemsEnCestaTalle'];
$itemsEnCestaColor=$_SESSION['itemsEnCestaColor'];
$var=$_POST["agregar"]; 
$cod=$_GET["cod"];

if (
$var == "Agregar"
   {
     if (
$item && $talle  && $color){ 
        if (!isset(
$itemsEnCestaCant) && !isset($itemsEnCestaTalle) && !isset($itemsEnCestaColor)){
        
$itemsEnCestaCant[$item]=$cantidad
        
$itemsEnCestaTalle[$item]=$talle;
        
$itemsEnCestaColor[$item]=$color;
        }else{ 
        foreach(
$itemsEnCestaCant as $k => $v){ 
        if (
$item==$k){ 
        
$itemsEnCestaCant[$k]+=$cantidad
        
$encontrado=1
        } 
        } 
        if (!
$encontrado$itemsEnCestaCant[$item]=$cantidad
        } 
        }  
        
$_SESSION['itemsEnCestaCant']=$itemsEnCestaCant
        
$_SESSION['itemsEnCestaTalle']=$itemsEnCestaTalle
        
$_SESSION['itemsEnCestaColor']=$itemsEnCestaColor
    }
if (
$cod != "")
  {
    unset (
$_SESSION['itemsEnCestaCant'][$cod]);
    unset (
$_SESSION['itemsEnCestaTalle'][$cod]);
    unset (
$_SESSION['itemsEnCestaColor'][$cod]);
    
$_SESSION['itemsEnCestaCant']=$itemsEnCestaCant
    
$_SESSION['itemsEnCestaTalle']=$itemsEnCestaTalle
    
$_SESSION['itemsEnCestaColor']=$itemsEnCestaColor;
  }
?>
 
<html>

<style type="text/css">
<!--
.lista {
    margin: 0px auto 20px auto;
    border-collapse: collapse;
}
.formulario{
    margin: 0px auto 20px auto;
}
-->
</style> 

<body> 
<!-- <form src="?=$PHP_SELF.?>" method="post"> -->
<!-------------------------------------------------------------------------------------------->
<div id="contenedor">
<form src="borrar.php" method="post">
<table width="393" class="formulario">
  <!--DWLayoutTable-->
  <br />
                    <thead>
                        <tr>
                            <th colspan="2"> Agregando producto</th>
                          <td width="34"></td>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td width="124">Código</td>
                            <td width="211"><input name="item" type="text" id="item" size="10" class="required number" /></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td height="34" valign="top">Talle</td>
                            <td valign="top"><input name="talle" type="text" id="talle" size="20" class="required" /></td>
                            <td></td>
                        </tr>
                        
                        <tr>
                          <td height="34" valign="top">Descripción</td>
                          <td valign="top"><input type="text" class="required" size="30" maxlength="200" /></td>
                          <td></td>
                        </tr>
                        <tr>
                          <td height="30" valign="top"><p>Color<br />
                          </p></td>
                          <td rowspan="3" valign="top"><p>
                            <input name="color" type="text" id="color" size="30" class="required" />
                            <br />
                            <br />
                            <input name="cantidad" type="text" id="cantidad" size="10" class="required number" />
                          </p></td>
                          <td></td>
                        </tr>
                        <tr>
                          <td height="11"></td>
                          <td></td>
                        </tr>
                        <tr>
                          <td height="31" valign="top">Cantidad</td>
                          <td></td>
                        </tr>
                        <tr>
                          <td height="1"></td>
                          <td></td>
                          <td></td>
                        </tr>
                        <tr>
                          <td height="36" colspan="3" valign="top"><div align="right">
                            <input name="agregar" type="submit" id="agregar" value="Agregar" />
                            <label></label>
                          </div></td>
                      </tr>
                        <tr>
                          <td height="1"></td>
                          <td></td>
                          <td></td>
                        </tr>
                    </tbody>
                    <tfoot>
                    </tfoot>
                </table>
  </form>
          </div>

<!--------------------------------------------------------------------------------------------->
<form src="borrar.php" method="post">
C&oacute;d Articulo
  <input type="text" name="item" size="20"><br>
Cuantas unidades <input type="text" name="cantidad" size="20"><br>
<input type="submit"  name="agregar" value="Agregar">
<br> 
</form> 
<table width="683" border="1" cellpadding="1" cellspacing="1" class="lista"><!--DWLayoutTable-->
  <thead>
<tr>
            <th width="179">Codigo Art</th>
            <th width="124">Imag&eacute;n</th>
            <th width="85">Talle</th>
            <th width="93">Color</th>
            <th width="148">Cantidad</th>
            <th width="21"></th>
        </tr>
  </thead>
        <tbody>
        <?php 
            
if (!isset($itemsEnCestaCant) && !isset($itemsEnCestaTalle) && !isset($itemsEnCestaColor)){
            foreach(
$itemsEnCestaCant as $k => $v){ 
        
//    $cant= $cant+$v;
            
echo '<form src="borrar.php" method="post">';
            echo 
'<tr><td><div align="center">'.$k.'</div></td><td><div align="center">IMAGEN</div></td> <td><div align="center">'.$talle.'</div></td><td><div align="center">'.$color.'</div></td><td><div align="center">'.$v.'</div></td><td><a href="borrar.php?cod='.$k.'"><img src="delete.png"/></a><br></td></tr>'
            echo 
'</form>';
            }
            }
            
?>
        
</table>
 
</body> 
</html>
  #2 (permalink)  
Antiguo 10/06/2010, 16:49
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 11 meses
Puntos: 1517
Respuesta: Carrito de compras simple en PHP problem!

Ok, perfecto, ahí está el código y ¿cuál es el problema? o ¿quieres que adivinemos?
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #3 (permalink)  
Antiguo 10/06/2010, 16:55
 
Fecha de Ingreso: diciembre-2005
Mensajes: 50
Antigüedad: 18 años, 4 meses
Puntos: 0
Respuesta: Carrito de compras simple en PHP problem!

perdoon! toy en la facu despistado jajaja..
el problema esta en que yo cargo el producto pero como que no me lo muestra, o no me lo carga .
Nose si estoy haciendo bien

$itemsEnCestaCant=$_SESSION['itemsEnCestaCant'];
$itemsEnCestaTalle=$_SESSION['itemsEnCestaTalle'];
$itemsEnCestaColor=$_SESSION['itemsEnCestaColor'];

o si el problema esta en que no me lo guarda.
Este carrito lo adapte del mas comun, que es igual a este, pero solo con 2 variables de entrada, item y cantidad, yo le adapte talles y colores.. pero no se que pasa..
que estoy haciendo mal?

Mil disculpas!! xD
  #4 (permalink)  
Antiguo 10/06/2010, 17:02
Avatar de juanito1712  
Fecha de Ingreso: mayo-2010
Ubicación: Valencia
Mensajes: 1.124
Antigüedad: 13 años, 11 meses
Puntos: 66
Respuesta: Carrito de compras simple en PHP problem!

buffff, menudo pastelón de codigo....
intenta ya no averiguar el porque, sino el donde de tu error, porque entre tanto código hace falta mucho valor para ponerse a mirar como funciona, quizá con dudas mas concretas recibas mas ayuda
  #5 (permalink)  
Antiguo 11/06/2010, 10:56
 
Fecha de Ingreso: diciembre-2005
Mensajes: 50
Antigüedad: 18 años, 4 meses
Puntos: 0
Respuesta: Carrito de compras simple en PHP problem!

ya estaa... lo solucione utilizando codigo de otro carrito..

alguien sabe como puedo hacer para pasar lo que esta guardado dentro de la sesion a un formulario? yo tenia pensado hacer un textarea oculto donde pongo todo lo de la sesion y lo envia, pero como coloco los datos ahi dentro?

Etiquetas: carrito, compras, simple
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:37.