Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/04/2016, 23:32
Avatar de aviweb2015
aviweb2015
 
Fecha de Ingreso: abril-2016
Ubicación: venezuela
Mensajes: 215
Antigüedad: 8 años
Puntos: 1
problemas en inventario

hola, tengo un problema con mi inventario resulta que a la hora de agregar los productos disponibles que hay solo me agrega el producto que esta de primero y si pulso sobre los otros productos no me los agrega me sigue agregando el primero nada mas de igual forma cuando ya el producto esta agregado no me deja agregar mas cantidad el producto ni restarle cantidad y tampoco eliminarlo anexo mi codigo para ver si me pueden ayudar con esto que de verdad me tiene mal, gracias de ante de mano

Código PHP:
Ver original
  1. <?php
  2.  
  3. ?>
  4. <?php
  5. include("conexion.php");
  6. ?>
  7.  
  8. <?php
  9. $resultado=mysql_query("SELECT * FROM servicios GROUP BY id");
  10.  
  11. echo "<table  class='striped responsive-table'>";
  12. echo "<tr>";
  13. echo "<th data-field='id' style='display:none'>Id</th>";
  14. echo "<th data-field='id'>Categias</th>";
  15. echo "<th data-field='id'>Producto</th>";
  16. echo "<th data-field='id'>Precio</th>";
  17. echo "<th data-field='id'>Imagen</th>";
  18. echo "<th data-field='id'>Agregar</th>";
  19. echo "</tr>";
  20. echo "<tr>";
  21.  
  22. while ($servicios=mysql_fetch_array($resultado)){
  23.  
  24. echo "<td style='display:none'>".$servicios['id']."</td>";
  25. echo "<td>".$servicios['idproductos']."</td>";
  26. echo "<td>".$servicios['descripcion']."</td>";
  27. echo "<td>".$servicios['precio']." BsF </td>";
  28. echo "<td><img src=".$servicios['imagen']." width='70' height='70'></td>";
  29. echo "<td>
  30. <a href='preparo_contrato.php?id=".$servicios['id']."&action=";
  31. if (isset($_SESSION['carro'][$servicios['id']])){
  32.  
  33. echo "removeProd' alt='Eliminar del carro'>
  34. <img src='img/remove_carro.png'
  35. width='38' height='38'
  36. alt='Eliminar del carro'
  37. title='Añadir producto al carrito'>";
  38. }
  39. else
  40. echo "add' alt='Añadir al carro'>
  41. <img src='img/add_carro.png'
  42. width='38' height='38' alt='Añadir al carrito'
  43. title='Añadir producto al carrito'>";
  44.  
  45.  
  46. echo "</tr>";
  47.  
  48. }
  49. echo "</table>";
  50. ?>
  51.  
  52. </div>
  53. <!-- fin para carga productos-->
  54.  
  55.  
  56. <div class="col s6">
  57.  
  58.  
  59.  
  60. <!--   tabla de  productos-->
  61. <a name='action'></a>
  62. <?php
  63. include("conexion.php");
  64. ?>
  65. <h5 class="black-text text-darken-4 center-align">Mis Productos Agregados</h5>
  66.  
  67.  
  68. <?php
  69. if (isset($_GET['id']))
  70. $id = $_GET['id'];
  71. else
  72. $id = 1;
  73.      
  74. if (isset($_GET['action']))
  75. $action = $_GET['action'];
  76. else
  77. $action = "empty";
  78.  
  79. switch($action){
  80.      
  81. case "add":
  82. if(isset($_SESSION['carro'][$id]))
  83. $_SESSION['carro'][$id]++;
  84. else
  85. $_SESSION['carro'][$id]=1;
  86. break;
  87.        
  88. case "remove":
  89. if(isset($_SESSION['carro'][$id]))
  90. {
  91. $_SESSION['carro'][$id]--;
  92. if($_SESSION['carro'][$id]==0)
  93. unset($_SESSION['carro'][$id]);
  94. }
  95. break;
  96.  
  97. case "removeProd":
  98. if(isset($_SESSION['carro'][$id])){
  99. unset($_SESSION['carro'][$id]);
  100. }
  101. break;
  102.  
  103.  
  104. case "mostrar":
  105. if(isset($_SESSION['carro'][$id])){
  106. continue;
  107. }
  108. break;
  109.  
  110.  
  111. case "empty":
  112. unset($_SESSION['carro']);
  113. break;
  114.            
  115.        
  116. }
  117.      
  118. if(isset($_SESSION['carro'])){
  119. echo "<form action='preparo_contrato.php' method='POST'>";
  120. echo "<table class='striped responsive-table'>";
  121. $totalcoste = 0;
  122.  
  123.  
  124. //Inicializamos el contador de productos seleccionados.
  125. $xTotal = 0;
  126.        
  127. echo "<tr>";
  128. echo "<td>Producto</td>";
  129. echo "<td>Cantidad</td>";
  130. echo "<td>Acción</td>";
  131. echo "<td colspan=4 align=right>Total</td>";
  132. echo "</tr>";
  133. echo "<tr><td colspan=5></td></tr>";
  134.  
  135.  
  136. foreach($_SESSION['carro'] as $id => $x){
  137. $resultado = mysql_query("SELECT * FROM servicios WHERE id ");
  138. $result=mysql_query($sql,$link);
  139. $mifila=mysql_fetch_array($resultado);    
  140. $id = $mifila['id'];
  141. $descripcion = $mifila['descripcion'];
  142. //acortamos el nombre del producto a 40 caracteres
  143. $descripcion = substr($descripcion,0,40);
  144. $precio = $mifila['precio'];
  145. //Coste por artículo según la cantidad elegida
  146. $coste = $precio * $x;
  147. //Coste total del carro
  148. $totalcoste = $totalcoste + $coste;
  149. //Contador del total de productos añadidos al carro
  150. $xTotal = $xTotal + $x;
  151.  
  152.  
  153. echo "<tr>";
  154. echo "<td align='left'>$descripcion</td>";//muestra pruducto en el carro
  155. echo "<td align='center'>$x<input type='hidden' name=chk_group3[] value='$x'>";
  156. echo "<input type='hidden' name=chk_group[] value='$id'></td>";
  157.    
  158.  
  159. //acciones para el carrito:
  160. echo "<td align='left'>";
  161. echo "<a href='preparo_contrato.php?id=". $id ."&action=add'><img src='img/aumentar.png' style='padding:0 0px 0 5px;' alt='Aumentar cantidad' /></a>";
  162. echo "<a href='preparo_contrato.php?id=". $id ."&action=remove'><img src='img/restar.png' alt='Reducir cantidad' /></a>";
  163. echo "<a href='preparo_contrato.php?id=". $id ."&action=removeProd'><img src='img/eliminar.png' alt='Reducir cantidad' /></a></td>";
  164.          
  165.  
  166. echo "<td align='right'> = </td>";
  167. echo "<td align='right' style='margin-left:10px'>$coste BsF.
  168. <input type='hidden' name=chk_group2[] value='$coste'>";
  169. echo "</tr>";
  170. $i++;
  171. }
  172.  
  173. //el total de la venta
  174. echo "<tr><td colspan='5'><hr></td></tr>";
  175. echo "<tr>";
  176. echo "<td colspan='4'><h5 class='right-align'><b>Total =</b></h5></td>";
  177. echo "<td align='right'><h5><b>$totalcoste</b> BsF.</h5>
  178. <input type='hidden' name=costetotal value='$totalcoste'></td>";
  179. echo "</tr>";
  180.      
  181. echo "<tr>";
  182. echo "<td align='left' colspan='5'>
  183. <input type=text placeholder='Buscar Cliente' autocomplete='off'
  184. title='BUSQUE POR NOMBRE O NÚMERO DE CÉDULA'
  185. style='background: white url(imagenes/lupa.png) no-repeat;
  186. background-position: 125px;' class='cajatexto2' id='inputString'
  187. name='cedulac' onKeyUp='lookup(this.value);' onBlur='fill();'></div>
  188. <div class='suggestionsBox' id='suggestions' style='display: none;'>
  189. <div class='suggestionList' id='autoSuggestionsList'>
  190. </div></div></td></tr>";?>
__________________
yoclens avilan