Ver Mensaje Individual
  #4 (permalink)  
Antiguo 14/10/2011, 04:59
loro25
(Desactivado)
 
Fecha de Ingreso: noviembre-2003
Mensajes: 59
Antigüedad: 20 años, 5 meses
Puntos: 0
Respuesta: crear el carrito de la compra

yo tengo el codigo asi

arriba he puesto
Código:
<?php
session_start();
if(isset($_SESSION['carrito']) || isset($_POST['productos'])){
	if(isset($_SESSION['carrito'])){
		$carrito_mio=$_SESSION['carrito'];
		$cantidad=$_POST['cantidad'];
		$productos=$_POST['productos'];
		$precio=$_POST['precio'];
		$carrito_mio[]=array("productos"=>$productos,"precio"=>$precio,"cantidad"=>$cantidad);
	}else{
		$productos=$_POST['productos'];
		$precio=$_POST['precio'];
		$cantidad=$_POST['cantidad'];
		$carrito_mio[]=array("productos"=>$productos,"precio"=>$precio,"cantidad"=>$cantidad);
		
		
	}

		$_SESSION['carrito']=$carrito_mio;
		

	
}

?>
y en donde suman el total los productos comprados y todo tengo puesto


Código:
			<?php
            $gastos=6;
		
			?>
			<?php
			if(isset($_SESSION['carrito'])){
			$total=0;
			
			for($i=0;$i<=count($carrito_mio)-1;$i ++){
			
			?>
			
			<tr>
              <td><?php  print $carrito_mio[$i]['productos']; ?>;</td>
              <td align="right"><?php  print $carrito_mio[$i]['precio']; ?>;</td>
              <td align="right"><?php print $carrito_mio[$i]['cantidad'];  ?>;</td>
              <td align="right"><?php  print $carrito_mio[$i]['precio'] * $carrito_mio[$i]['cantidad']; ?></td>
            </tr>
			<?php
			$total=$total + ($carrito_mio[$i]['precio'] * $carrito_mio[$i]['cantidad']);
			}
			}
			?>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>gastos de envio: </td>
              <td align="right"><?php print $gastos; ?> &euro; ;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td><strong>Total:</strong></td>
              <td align="right"> <?php print $total; ?></td>
Queria saber si tengo mal el codigo?