Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/02/2010, 12:43
etisdemian
 
Fecha de Ingreso: octubre-2009
Mensajes: 357
Antigüedad: 14 años, 5 meses
Puntos: 1
aplicar descuento a un valor del carro de compras

hola muchachos, les cuento que tengo un carrito de compras que , en algunos productos se aplica un descuento% ,los que tengan una cierta marca(-).

ahora como acarreo ese valor a las sumas y al resultado final?

les envio una sintesis del codigo...

cualquier guia, muy agradecido.

Código PHP:
Ver original
  1. <?php
  2. //datos
  3. @mysql_pconnect("localhost","root","xxxx");
  4. ?>
  5. <?php
  6. //conexion
  7.   $resultado = mysql_query("select in_imag, in_titulo, in_autor, in_venta_iva, in_ISBN, in_id, in_editor2, in_edicion, marca from inventario where in_oferta like '%P%' ") or die(mysql_error());
  8.     $num_resultados = @mysql_num_rows($resultado);
  9.   for ($i=0; $i <$num_resultados; $i++)
  10.   {
  11.      $row = mysql_fetch_array($resultado);
  12.        ?>}
  13.  
  14.  <?php                  
  15. //utilizo este codigo para otorgar un descuento a los productos marcados con"-"
  16. $marca= $row['marca'];
  17. if($marca == "-"){
  18. $tot = $cantidad - ($cantidad*10/100);
  19. $total = number_format($tot,0);
  20. ?>
  21. <?php echo $total;
  22. }
  23. ?>
  24.  
  25. <?php
  26. //lo siguiente agrega el producto
  27. if(!$carro || !isset($carro[md5($row['in_id'])]['identificador']) || $carro[md5($row['in_id'])]['identificador']!=md5($row['in_id'])){
  28. ?>
  29. <a href="agregacar.php?<?php echo SID ?>&id=<?php echo $row['in_id']; ?>">
  30. <img src="_imagenes/shop2.jpg" width="64" height="15" border="0" title="Agregar al Carrito"></a><?php }?>
  31.  
  32. <?php  
  33. //este es el script que agrega el producto al carro
  34. extract($_REQUEST);
  35. mysql_connect("localhost","root","xxxxx");
  36.  
  37. if(!isset($cantidad)){$cantidad=1;}
  38. $qry=mysql_query("select * from inventario where in_id='".$id."'");
  39. $row=mysql_fetch_array($qry);
  40.  
  41. if(isset($_SESSION['carro']))
  42. $carro=$_SESSION['carro'];
  43. $carro[md5($id)]=array('identificador'=>md5($id),
  44. 'cantidad'=>$cantidad,'in_titulo'=>$row['in_titulo'],
  45. 'in_venta_iva'=>$row['in_venta_iva'],'id'=>$id);
  46. $_SESSION['carro']=$carro;
  47. header("Location:zcarro.php?".SID);
  48. ?>  
  49.  
  50. <?php  
  51. //pagina que muestra los productos
  52. if(isset($_SESSION['carro']))
  53. $carro=$_SESSION['carro'];else $carro=false;
  54. ?>
  55. <?php  
  56. if($carro){
  57. ?>
  58. <?php
  59. $color=array("#ffffff","#f0f0f0");
  60. $contador=0;
  61. $suma=0;
  62. foreach($carro as $k => $v){
  63. $subto=$v['cantidad']*$v['in_venta_iva'];
  64. $suma=$suma+$subto;
  65. $contador++;
  66. ?>
  67. <form name="a<?php echo $v['identificador'] ?>" method="post"
  68. action="agregacar.php?<?php echo SID ?>" id="a<?php echo $v['identificador'] ?>">
  69. <?php echo $color[$contador%2]; ?>
  70. <?php echo $v['in_titulo'] ?>
  71. <?php echo $v['in_venta_iva'] ?>
  72. <?php echo $v['cantidad'] ?>
  73.  
  74. <input name="cantidad" type="text" id="cantidad"
  75. value="<?php echo $v['cantidad'] ?>" size="8">
  76. <input name="id" type="hidden" id="id"
  77. value="<?php echo $v['id'] ?>">
  78.  
  79. <a href="borracar.php?<?php echo SID ?>&id=<?php echo $v['id'] ?>">
  80. <img src="_imagenes/delete.gif" width="23" height="23" border="0"></a>
  81.  
  82. <input name="imageField" type="image" src="_imagenes/8.jpg" width="20" height="20" border="0">
  83. </form>
  84. <?php } ?>
  85. <?php echo count($carro);
  86.  ?>
  87. <span class="Estilo7">SubTotal: $<?php echo number_format($suma,0);?>
  88. </span>  
  89.  
  90. <div id="compra">
  91. <a href="zpaso4.php?<?php echo SID;?>&costo=<?php echo $suma; //link que se lleva los valores?>">
  92. <img src="_imagenes/comprar.png" alt="comprar" /></a>
  93. <a href="zpago.php?<?php echo SID;?>&costo=<?php echo $suma; ?>"></a>
  94. <a href="zpago.php?<?php echo SID;?>&costo=<?php echo $suma; ?>"></a>
  95. <a href="ztodo.php"><img src="_imagenes/rechazar.png" alt="Mas Tarde" /></a>
  96. </div>
  97. </span>  
  98. <br />
  99. <a href="zpago.php?<?php echo SID;?>&costo=<?php echo $suma; ?>"></a>
  100.  
  101. <?php }else{ ?>
  102. <p align="center"><a href="ztodo.php?<?php echo SID;?>"><span class="Estilo6">No hay productos seleccionados</span>
  103. </a>
  104. <?php }?>


he pensado en..
<?php
$marca=$row['marca'];
if($marca == "-"){
$suma = $suma - ($suma*10/100);
$total = number_format($suma,0);

//pero la variable suma no tiene nada que ver me parece
?>
<span class="Estilo7">SubTotal: $<?php echo number_format($suma,0);?></span>