/backend/ajax/CargarDatosProductosxColor.php

https://gitlab.com/scsistemas/superprime · PHP · 125 lines · 84 code · 31 blank · 10 comment · 13 complexity · 3031b0fc4744c3f3b4c87d63d898dd2a MD5 · raw file

  1. <?php
  2. include '../config/definitions.php';
  3. session_start();
  4. $salir = 0;
  5. $i = 0;
  6. while (($salir ==0) && ($_POST['CodProAnt']!='')){
  7. if ($_SESSION['product']['producto']['ColoresProducto'][$i]['CodColor'] == $_POST['CodProAnt']){
  8. $_SESSION['product']['producto']['ColoresProducto'][$i]['ColorPrinc'] = $_POST['ColorPri'];
  9. $_SESSION['product']['producto']['ColoresProducto'][$i]['DescWeb'] = $_POST['DesColorWeb'];
  10. if ($_POST['CheckSec'])
  11. $_SESSION['product']['producto']['ColoresProducto'][$i]['ColorSec'] = $_POST['ColorSec'];
  12. else
  13. $_SESSION['product']['producto']['ColoresProducto'][$i]['ColorSec'] = '';
  14. if ($_POST['CheckWeb'] == 1)
  15. $_SESSION['product']['producto']['ColoresProducto'][$i]['MostrarWeb'] = 'S';
  16. else
  17. $_SESSION['product']['producto']['ColoresProducto'][$i]['MostrarWeb'] = 'N';
  18. $salir = 1;
  19. }
  20. $i = $i + 1;;
  21. }
  22. if ($_SESSION['product'][$_POST['CodProAnt']]){
  23. // guardar precios
  24. $_SESSION['product'][$_POST['CodProAnt']]['colorProd']['PreciosWeb']['Precio'] = $_POST['PrecioWeb'];
  25. if ($_POST['PorcDesc'] > 0)
  26. {
  27. $_SESSION['product'][$_POST['CodProAnt']]['colorProd']['PreciosWeb']['PorcDesc'] = $_POST['PorcDesc'];
  28. //number_format($numero, 2, ',', '.')
  29. $precio = str_replace('.', '',$_POST['PrecioWeb']);
  30. $precio = str_replace(',','.',$precio);
  31. $precio = floatval($precio);
  32. $porDes = str_replace('.', '',$_POST['PorcDesc']);
  33. $porDes = str_replace(',','.',$porDes);
  34. $porDes = floatval($porDes);
  35. $montD = $precio - (($precio /100) * $porDes);
  36. $_SESSION['product'][$_POST['CodProAnt']]['colorProd']['PreciosWeb']['MontoDesc'] = number_format($montD, 2, ',', '.');
  37. $iva = $montD * 0.12;
  38. $total = $montD + $iva;
  39. $_SESSION['product'][$_POST['CodProAnt']]['colorProd']['PreciosWeb']['Total'] = number_format($total, 2, ',', '.');
  40. $_SESSION['product'][$_POST['CodProAnt']]['colorProd']['PreciosWeb']['MontoIVA'] = number_format($iva, 2, ',', '.');
  41. }
  42. else
  43. {
  44. $_SESSION['product'][$_POST['CodProAnt']]['colorProd']['PreciosWeb']['MontoDesc'] = 0;
  45. $_SESSION['product'][$_POST['CodProAnt']]['colorProd']['PreciosWeb']['PorcDesc'] = 0;
  46. $_SESSION['product'][$_POST['CodProAnt']]['colorProd']['PreciosWeb']['Total'] = $_POST['PrecioWeb'];
  47. $precio = str_replace('.', '',$_POST['PrecioWeb']);
  48. $precio = str_replace(',','.',$precio);
  49. $precio = floatval($precio);
  50. $_SESSION['product'][$_POST['CodProAnt']]['colorProd']['PreciosWeb']['MontoIVA'] = number_format(($precio / 100) * 12, 2, ',', '.');
  51. }
  52. //guardar selección de fotos
  53. $imagenes = json_decode($_POST['imagenes']);
  54. $_SESSION['product'][$_POST['CodProAnt']]['colorProd']['ImagenesSelec'] = $imagenes;
  55. //Inicio actualizar tallas seleccionadas
  56. $t = json_decode($_POST['tallasA']);
  57. for ($i=0; $i < count($_SESSION['product'][$_POST['CodProAnt']]['colorProd']['tallas']); $i++)
  58. {
  59. $_SESSION['product'][$_POST['CodProAnt']]['colorProd']['tallas'][$i]['MostrarWeb'] = 'N';
  60. foreach ($t as $value)
  61. {
  62. if ($_SESSION['product'][$_POST['CodProAnt']]['colorProd']['tallas'][$i]['CodTalla'] == $value)
  63. {
  64. $_SESSION['product'][$_POST['CodProAnt']]['colorProd']['tallas'][$i]['MostrarWeb'] = 'S';
  65. }
  66. }
  67. }
  68. //Fin actualizar tallas seleccionadas
  69. }
  70. if (!$_SESSION['product'][$_POST['CodProAct']]){
  71. $url = $urlWS. 'service=generalservices&metodo=ObtenerDetalleColor&p_cod_prod='. $_POST['CodProducto'].'&p_color='.$_POST['CodProAct'];
  72. $ch = curl_init();
  73. curl_setopt($ch, CURLOPT_URL,$url);
  74. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  75. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  76. $resultDataProduct = curl_exec($ch);
  77. //print_r($resultDataProduct) ;
  78. curl_close($ch);
  79. $prueba = json_encode($_SESSION['product']);
  80. $prueba = str_replace('á','&aacute;',$prueba);
  81. $prueba = str_replace('é','&eacute;',$prueba);
  82. $prueba = str_replace('í','&iacute;',$prueba);
  83. $prueba = str_replace('ó','&oacute;',$prueba);
  84. $prueba = str_replace('ú','&uacute;',$prueba);
  85. $prueba = str_replace('ñ','&ntilde;',$prueba);
  86. $_SESSION['product'] = json_decode($prueba,true);
  87. //array_push($_SESSION['product'][$_POST['CodProAct']],json_decode($resultDataProduct,true));
  88. $_SESSION['product'][$_POST['CodProAct']] = json_decode($resultDataProduct,true);
  89. }
  90. //echo $resultDataProduct;
  91. echo json_encode($_SESSION['product'])
  92. //echo json_encode($_POST);
  93. //print_r($_SESSION['product']) ;
  94. ?>