Ver Mensaje Individual
  #6 (permalink)  
Antiguo 30/01/2011, 07:40
sergy1989_6
 
Fecha de Ingreso: enero-2011
Mensajes: 7
Antigüedad: 13 años, 3 meses
Puntos: 0
Respuesta: Problema con carrito

vale aora tengo otro problemilla con esto del carrito.. aver si me podeis exar una mano..., estoy intentando acer ke cada vez ke pike en el mismo producto me aumente la cantidad no ke me aga un nuevo td con el producto, estoy con este codigo, pero estoy atascao con eso
Código PHP:
<?

class carrito {
    
//atributos de la clase
       
var $num_productos;
                var 
$array_foto_prod;
       var 
$array_cod_prod;
       var 
$array_nom_prod;
       var 
$array_precio_prod;

    
//constructor. Realiza las tareas de inicializar los objetos cuando se instancian
    //inicializa el numero de productos a 0
    
function carrito () {
           
$this->num_productos=0;
    }
    
    
//Introduce un producto en el carrito. Recibe los datos del producto
    //Se encarga de introducir los datos en los arrays del objeto carrito
    //luego aumenta en 1 el numero de productos
    
function introduce_producto($cod_prod,$nom_prod,$precio_prod,$foto_prod){
            
$this->array_foto_prod[$this->num_productos]=$foto_prod;
        
$this->array_cod_prod[$this->num_productos]=$cod_prod;
        
$this->array_nom_prod[$this->num_productos]=$nom_prod;
        
$this->array_precio_prod[$this->num_productos]=$precio_prod;
        
$this->num_productos++;
    }

    
//Muestra el contenido del carrito de la compra
    //ademas pone los enlaces para eliminar un producto del carrito
    
function imprime_carrito(){
        
$suma 0;

        echo 
'<table width="100%" border="0" cellspacing="0">
                    <tr>
                      <th width="32%" bgcolor="#999999" scope="col">ARTICULO/S</th>
                                                                                        <th width="37%" bgcolor="#999999" scope="col">NOMBRE DEL PRODUCTO</th>
                      <th width="37%" bgcolor="#999999" scope="col">CANTIDAD</th>
                      <th width="31%" bgcolor="#999999" scope="col">PRECIO</th>
                                                                                        <th width="31%" bgcolor="#999999" scope="col"> </th>
                    </tr>
                  </table>'
;

                    echo 
"<table width='100%' height='211' border='0' cellpadding='0' cellspacing='0'>";
        for (
$i=0;$i<$this->num_productos;$i++){
            if(
$this->array_cod_prod[$i]!=0){
                echo 
'<tr>';
                echo 
"<th width='32%' height='110' rowspan='2' align='left' valign='top' bgcolor='#CCCCCC' scope='col'>"$this->array_foto_prod[$i]."</th>";
                echo 
"<td width='32%' height='110' rowspan='2' align='left' valign='top' bgcolor='#CCCCCC' scope='col'>" $this->array_nom_prod[$i]. "</td>";
                echo 
"<th width='18%' rowspan='2' align='right' valign='middle' bgcolor='#CCCCCC' scope='col'><p class='NARUTO'>
                        <label>
                        <input name='textfield4' type='text' id='textfield' value='1' size='10' />
                        </label>
                      </p></th>"
;    
             echo 
"<th width='19%' height='74' align='left' valign='bottom' bgcolor='#CCCCCC' scope='col'><img src='../../../Sergio Ramosphp/Imagenes/+1.png' width='28' height='27' /></th>";
    echo 
"<th width='18%' rowspan='2' align='center' valign='top' bgcolor='#CCCCCC' scope='col'><p>&nbsp;</p>
                      <p class='titulo'>"
$this->array_precio_prod[$i]."</p></th>";
                echo 
"<td><a href='eliminar_producto.php?linea=$i'>Eliminar producto</td>";
                echo 
'</tr>';
                 echo 
'<tr>';
     echo 
"<th height='63' align='left' valign='top' bgcolor='#CCCCCC' scope='col'><img src='../../../Sergio Ramosphp/Imagenes/-1.png' width='28' height='27' /></th>";
                  echo 
'</tr>';
                
$suma += $this->array_precio_prod[$i];
            }
        }
        
        
//muestro el total
        
echo "<tr><td><b>TOTAL:</b></td><td> <b>$suma</b></td><td>&nbsp;</td></tr>";
        
//total más IVA
        
echo "<tr><td><b>IVA (16%):</b></td><td> <b>" $suma 1.16 "</b></td><td>&nbsp;</td></tr>";
        echo 
"</table>";
    }
    
    
//elimina un producto del carrito. recibe la linea del carrito que debe eliminar
    //no lo elimina realmente, simplemente pone a cero el id, para saber que esta en estado retirado
    
function elimina_producto($linea){
        
$this->array_cod_prod[$linea]=0;
    }

//inicio la sesión
session_start();
//si no esta creado el objeto carrito en la sesion, lo creo
if (!isset($_SESSION["ocarrito"])){
    
$_SESSION["ocarrito"] = new carrito();
}
?>
con esto saco una nueva fila pero nose como implementar lo de la cantidad, gracias de antemano