PHP - carrito php

 
Vista:

carrito php

Publicado por felix (1 intervención) el 11/06/2013 22:06:47
Buenas noches haber si me podeis ayudar, quiero que cuando no haya productos que no muestre nada, gracias


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
if (isset($_POST['id_txt'])){
	$id=$_POST['id_txt'];
	$nombre=$_POST['nombre'];
	$imagen=$_POST['imagen'];
	$precio=$_POST['precio'];
	$cantidad=$_POST['cantidad'];
	$mi_carrito[]=array('id'=>$id,'nombre'=>$nombre,'imagen'=>$imagen,'precio'=>$precio,'cantidad'=>$cantidad);
}
 
if (isset($_SESSION['carrito'])){
	$mi_carrito=$_SESSION['carrito'];
	if(isset($_POST['id_txt'])){
		$id=$_POST['id_txt'];
		$nombre=$_POST['nombre'];
		$imagen=$_POST['imagen'];
		$precio=$_POST['precio'];
		$cantidad=$_POST['cantidad'];
		$pos=-1;
		for($i=0;$i<count($mi_carrito);$i++){
			if($id==$mi_carrito[$i]['id']){
				$pos=$i;
				}
			}
			if($pos<>-1){
				$cuanto=$mi_carrito[$pos]['cantidad']+$cantidad;
				$mi_carrito[$pos]=array('id'=>$id,'nombre'=>$nombre,'imagen'=>$imagen,'precio'=>$precio,'cantidad'=>$cuanto);
				}else{
		$mi_carrito[]=array('id'=>$id,'nombre'=>$nombre,'imagen'=>$imagen,'precio'=>$precio,'cantidad'=>$cantidad);
				}
	}
}
if(isset($_POST['id2'])){
  $indice=$_POST['id2'];
  $cuanto=$_POST['cantidad2'];
  $mi_carrito[$indice]['cantidad']=$cuanto;
}
 
if (isset($_POST['id3'])){
	$indice=$_POST['id3'];
	$mi_carrito[$indice]=NULL;
}
if(isset($mi_carrito)) $_SESSION['carrito']=$mi_carrito;
 
?>
<!DOCTYPE HTML>
<html lang="es">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/style.css" />
<title>Catalogo de moviles</title>
<script language="javascript" src="js/jquery-1.3.min.js"></script>
<script type="text/javascript">
function mainmenu(){
$(" #nav ul ").css({display: "none"});
$(" #nav li").hover(function(){
	$(this).find('ul:first:hidden').css({visibility: "visible",display: "none"}).slideDown(400);
	},function(){
		$(this).find('ul:first').slideUp(400);
	});
}
$(document).ready(function(){
	mainmenu();
});
</script>
</head>
<body>
<header>
<div class="cabecera">
 
<div class="contenedorheader">
 
<?php include("includes/logo.php"); ?>
  </div>
  </div>
   </header>
  <div class="colorMenu">
  <?php include("includes/menu.php"); ?>
 
  <div class="contenedorcontenido">
<article>
<div class="cabezerafondo">
 <h2>Carrito de la Compra</h2>
</div>
<div class="registro">
<?php if($_SESSION['Total']>0){?>
 <table class="tablacarrito"  width="100%" border="0">
  <tr>
    <td bgcolor="#B8D84C">NOMBRE</td>
    <td bgcolor="#B8D84C">IMAGEN</td>
    <td bgcolor="#B8D84C">PRECIO</td>
    <td bgcolor="#B8D84C">CANTIDAD</td>
     <td colspan="2" bgcolor="#B8D84C">SUBTOTAL</td>
  </tr>
  <?php
  if(isset($mi_carrito)){
	  $total=0;
	  for($i=0;$i<count($mi_carrito);$i++){
		if($mi_carrito[$i]<>NULL)
		{
  ?>
  <tr>
    <td><?php echo $mi_carrito[$i]['nombre'];?></td>
    <td><img src="documentos/articulos/<?php echo $mi_carrito[$i]['imagen'];?>" width="40" height="40" /></td>
    <td><?php echo $mi_carrito[$i]['precio'];?></td>
    <td>
    <form action="" method="post" name="actualizo">
      <input name="id2" type="hidden" value="<?php echo $i;?>">
      <input name="cantidad2" type="text1" value="<?php echo $mi_carrito[$i]['cantidad'];?>" maxlength="2">
      <input name="input" type="image" src="images/ico_actualizar.png">
    </form></td>
    <?php
	$subtotal=$mi_carrito[$i]['precio']*$mi_carrito[$i]['cantidad'];
	$total=$total+$subtotal;
	?>
    <td><?php echo $subtotal;?></td>
    <td>
    <form action="" method="post">
    <input name="id3" type="hidden" value="<?php echo $i ?>" />
    <input name="" type="image" src="images/ico_eliminar.png" />
    </form>
    </td>
  </tr>
  <?php
		}
    }
 
	  }
  ?>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td bgcolor="#B8D84C">TOTAL</td>
    <td colspan="2"><?php
	if(isset($total))
	echo $total;
	$_SESSION['Total']=$total;
	?></td>
  </tr>
</table>
 
 <a href="javascript:history.back(1);"> volver</a> </div>
   <?php  }?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
-1
Responder