PHP - Problemas con carrito de compra

 
Vista:

Problemas con carrito de compra

Publicado por Matias (4 intervenciones) el 08/02/2012 00:52:53
Buenas este es el codigo que tengo del carrito de compra y el error que muestra al actualizar la cantidad del pedido:

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
145
146
147
148
149
150
151
<?php
session_start();
if(isset($_SESSION['carrito']) || isset($_POST['id_articulo'])){
	if(isset($_SESSION['carrito'])){
			if(isset($_POST['id_articulo'])){
				$carrito_actual = $_SESSION['carrito'];
				$id_articulo = $_POST['id_articulo'];
				$descripcion = $_POST['descripcion'];
				$precio = $_POST['precio'];
				$cantidad = $_POST['cantidad'];
				$pos = -1;
				for ($i=0; $i<= count($carrito_actual)-1; $i++){
				if($id_articulo == $carrito_actual[$i]['id_articulo']) {
					$pos = $i;
							}
				}
				if($pos != -1){
				$cant = $carrito_actual[$pos]['cantidad'] + $cantidad;
				$carrito_actual[$pos]=array("id_articulo"=>$id_articulo,"desc_art"=>$descripcion,"precio"=>$precio,"cantidad"=>$cant);
				} else {
				$carrito_actual[]=array("id_articulo"=>$id_articulo,"desc_art"=>$descripcion,"precio"=>$precio,"cantidad"=>$cantidad);
				}
				}
		} else {
			$id_articulo = $_POST['id_articulo'];
			$descripcion = $_POST['descripcion'];
			$precio = $_POST['precio'];
			$cantidad = $_POST['cantidad'];
			$carrito_actual[]=array("id_articulo"=>$id_articulo,"desc_art"=>$descripcion,"precio"=>$precio,"cantidad"=>$cantidad);
				}
 
			if (isset($_POST['cantidad2'])) {
				$id = $_POST['id'];
				$cant2= $_POST['cantidad2'];
				$carrito_actual[$id]['cantidad']=$cant2;
			}
$_SESSION['carrito']=$carrito_actual;
}
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/estudio.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Black Sheep</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<style type="text/css">
<!--
.Estilo2 {
	font-size: 26px;
	color: #333333;
}
.Estilo3 {color: #999999}
body {
	margin-left: 0%;
	margin-top: 0%;
	margin-right: 0%;
	margin-bottom: 0%;
}
-->
</style>
</head>
<body>
 
<div id="wrap">
 
<div id="header">
  <table width="100%" border="0">
  <tr>
    <td width="76%" height="51"><p><a href="#" class="Estilo2">Black Sheep</a></p>
      <p><a href="#" class="Estilo3">Estudio Grafcio, Hughes</a></p></td>
    <td width="24%"><p>&nbsp;</p>
      <p align="right"> <a href="usuarios.php">Iniciar sesion </a>| <a href="nuevo_usuario.php">Registrarse </a> </p></td>
  </tr>
</table>
</div>
 
<div id="menu">
<ul>
<li><a href="base.php">Inicio</a></li>
<li><a href="buscador.php">Buscador</a></li>
<li><a href="productos.php">Productos</a></li>
<li><a href="contacto.php">Contacto</a></li>
<li><a href="usuarios.php">Usuarios</a></li>
<li><a href="listado_newsletter_maestro.php">Noticias</a></li>
 
<li></li>
 
</ul>
 
</div>
 
 
<div id="content"><!-- InstanceBeginEditable name="editar" -->
  <p>Volver atras</p>
  <p align="center">&nbsp;</p>
  <p align="center"><strong>Carrito de compra</strong></p>
  <p>&nbsp;</p>
  <table width="90%" border="0">
    <tr>
      <td width="45%" bgcolor="#009999"><div align="center"><strong>Producto</strong></div></td>
      <td width="18%" bgcolor="#009999"><div align="center"><strong>Precio </strong></div></td>
      <td width="18%" bgcolor="#009999"><div align="center"><strong>Cantidad</strong></div></td>
      <td width="19%" bgcolor="#009999"><div align="center"><strong>Total</strong></div></td>
    </tr>
    <tr>
	<?php
	if(isset($_SESSION['carrito'])){
	$total=0;
	for($i=0;$i<=count($carrito_actual)-1; $i++) {
 
	?>
      <td valign="top"><?php print $carrito_actual[$i]['desc_art'];?></td>
      <td valign="top"><div align="right"> $ <?php print $carrito_actual[$i]['precio']; ?></div>  </td>
      <td valign="top"><div align="center">
        <form id="form1" name="form1" method="post" action="carrito_compra.php">
              <input name="id" type="hidden" id="id" value="<? print $i;  ?>" />
              <input name="cantidad2" type="text" id="cantidad2" value="<?php print $carrito_actual[$i]['cantidad']; ?>" size="2" />
              <input type="image" name="imageField" src="images/actualizar.png" />
        </form>
        </div></td>
      <td valign="top"><div align="right">$ <?php print $carrito_actual[$i]['precio'] * $carrito_actual[$i]['cantidad'] ?></div></td>
    </tr>
	<?php
	$total=$total + ($carrito_actual[$i]['precio'] * $carrito_actual[$i]['cantidad']);
	}
	}
	?>
    <tr>
      <td>&nbsp;</td>
      <td><div align="right"></div></td>
      <td><div align="right"><strong>Total</strong></div></td>
      <td align="right"> $ <?php print $total; ?> </td>
    </tr>
  </table>
  <p>&nbsp;  </p>
<!-- InstanceEndEditable --></div>
<div style="clear: both;"> </div>
</div>
 
<div id="footer">
  <p><a href="http://www.templatesold.com/" target="_blank">By Estudio</a></p>
</div>
</div>
 
</body>
<!-- InstanceEnd --></html>



El error que muestra al actualizar la cantidad de un producto es:


Notice: Undefined offset: 0 in C:\wamp\www\Estudio\carrito_compra.php on line 117
Call Stack
# Time Memory Function Location
1 0.0009 390440 {main}( ) ..\carrito_compra.php:0
$
( ! ) Notice: Undefined offset: 0 in C:\wamp\www\Estudio\carrito_compra.php on line 118

Undefined offset: 0 in C:\wamp\www\Estudio\carrito_compra.php on line 122

Notice: Undefined offset: 0 in C:\wamp\www\Estudio\carrito_compra.php on line 126
Notice: Undefined offset: 0 in C:\wamp\www\Estudio\carrito_compra.php on line 129
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder