Advertisement
Guest User

Untitled

a guest
Jan 9th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.77 KB | None | 0 0
  1. <?php
  2. header('Content-type: text/xml');
  3. $host = "d58093.mysql.zone.ee";
  4. $user = "d58093sa114985";
  5. $pass = "";
  6. $database = "d58093_bredencom";
  7. $con = mysqli_connect($host, $user, $pass, $database);
  8. if(mysqli_connect_errno()){
  9. trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR);
  10. }
  11. mysqli_set_charset($con, 'utf8');
  12.  
  13.  
  14. ////////////////////////
  15. //SUURUSTE SELEKTEERIMINE
  16. ////////////////////////
  17.  
  18.  
  19. //Valime laost kõik tooted, mille laoseis on suurem, kui 0
  20. $queryID_s1 = 'SELECT product_id, otp_id, model, quantity, price, special, extra, extra2 FROM jk2031_otp_data GROUP BY product_id DESC';
  21.  
  22. //Valime tooted, mis vastavad 50/56 suurusele ehk 0-1 kuud; 0-1 aastat; 35/38; 39/42 ja otsime suuruse ID'de põhiselt (76, 75, 81, 123)
  23. //$queryID_s1 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (76, 75, 81, 123) ORDER BY product_id ASC ';
  24.  
  25. //Valime tooted, mis vastavad 62/68
  26. $queryID_s2 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (105, 117,81, 82, 75, 76, 116, 77, 109) ORDER BY product_id DESC';
  27.  
  28. //Valime tooted, mis vastavad 74/80
  29. $queryID_s3 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (99, 118, 81, 77, 109, 110, 78) ORDER BY product_id DESC';
  30.  
  31. //Valime tooted, mis vastavad 86/92
  32. $queryID_s4 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (100, 82, 454, 121, 110, 78, 111, 79) ORDER BY product_id DESC';
  33.  
  34. //Valime tooted, mis vastavad 98/104
  35. $queryID_s5 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (101, 82, 83, 454, 121, 78,111,79,112) ORDER BY product_id DESC';
  36.  
  37. //Valime tooted, mis vastavad 110/116
  38. $queryID_s6 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (102, 83, 454, 121, 78, 111, 79, 112) ORDER BY product_id DESC';
  39.  
  40. //Valime tooted, mis vastavad 122/128
  41. $queryID_s7 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (103, 83, 120, 454, 121, 79, 112, 80, 113) ORDER BY product_id DESC';
  42.  
  43. //Valime tooted, mis vastavad 134/140
  44. $queryID_s8 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (104, 120, 454,121, 79, 112, 80, 113) ORDER BY product_id DESC';
  45.  
  46. //Valime tooted, mis vastavad 146/152
  47. $queryID_s9 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (459, 468, 79, 112, 80) ORDER BY product_id DESC';
  48.  
  49. //Valime tooted, mis vastavad 158/164
  50. $queryID_s10 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (460, 468, 79, 80, 534) ORDER BY product_id DESC';
  51.  
  52. //Valime tooted, mis vastavad S
  53. $queryID_s11 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (468, 120, 79, 80, 113, 534) ORDER BY product_id DESC';
  54.  
  55. //Valime tooted, mis vastavad M
  56. $queryID_s12 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (469, 120, 79, 80, 113, 534) ORDER BY product_id DESC';
  57.  
  58. //Valime tooted, mis vastavad L
  59. $queryID_s13 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (470, 120, 113, 534) ORDER BY product_id DESC';
  60.  
  61. //Valime tooted, mis vastavad XL
  62. $queryID_s14 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (471, 120, 86, 113, 534) ORDER BY product_id DESC';
  63.  
  64.  
  65. ////////////////////////
  66. //VANUSTE SELEKTEERIMINE
  67. ////////////////////////
  68.  
  69. //Valime tooted, mis vastavad 0-2 kuud
  70. $queryID_v1 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (123, 117, 81, 82, 75, 76, 105) ORDER BY product_id DESC';
  71.  
  72. //Valime tooted, mis vastavad 2-6 kuud
  73. $queryID_v2 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (117, 118, 81, 82, 76, 116, 77, 109, 110, 99, 100, 101) ORDER BY product_id DESC';
  74.  
  75. //Valime tooted, mis vastavad 6-12 kuud
  76. $queryID_v3 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (117, 118, 81, 82, 77, 109, 110, 99, 100, 101) ORDER BY product_id DESC';
  77.  
  78. //Valime tooted, mis vastavad 1-2 aastat
  79. $queryID_v4 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (81, 82, 454, 121, 110, 78, 111, 79, 99, 100, 101) ORDER BY product_id DESC';
  80.  
  81. //Valime tooted, mis vastavad 2-3 aastat
  82. $queryID_v5 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (82, 83, 454, 121, 110, 78, 111, 79, 112, 100, 101) ORDER BY product_id DESC';
  83.  
  84. //Valime tooted, mis vastavad 3-4 aastat
  85. $queryID_v5 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (83, 454, 121, 111, 79, 112, 101, 102) ORDER BY product_id DESC';
  86.  
  87. //Valime tooted, mis vastavad 4-5 aastat
  88. $queryID_v6 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN 83, 454, 121, 79, 112, 101, 102) ORDER BY product_id DESC';
  89.  
  90. //Valime tooted, mis vastavad 5-6 aastat
  91. $queryID_v7 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (83, 454, 121, 79, 112, 102, 103) ORDER BY product_id DESC';
  92.  
  93. //Valime tooted, mis vastavad 6-8 aastat
  94. $queryID_v8 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (83, 129, 454, 121, 79, 112, 86, 113, 102, 103, 104) ORDER BY product_id DESC';
  95.  
  96. //Valime tooted, mis vastavad 8-10 aastat
  97. $queryID_v9 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (120, 454, 121, 79, 86, 113, 103, 104, 459) ORDER BY product_id DESC';
  98.  
  99. //Valime tooted, mis vastavad 10-12 aastat
  100. $queryID_v10 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (120, 79, 86, 113, 104, 459) ORDER BY product_id DESC';
  101.  
  102. //Valime tooted, mis vastavad 12+ aastat
  103. $queryID_v11 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (120, 79, 86, 113, 534, 439, 460, 468, 469) ORDER BY product_id DESC';
  104.  
  105. //Valime tooted, mis vastavad täiskasvanud
  106. $queryID_v12 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (120, 79, 86, 113, 534, 460, 470, 469, 468, 471) ORDER BY product_id DESC';
  107.  
  108.  
  109.  
  110. /////// PEAÜMBERMÕÕDU SEKTSIOON
  111.  
  112. //Valime tooted, mis vastavad 35/38
  113. //$queryID = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (76, 75, 81, 123) ORDER BY product_id DESC';
  114.  
  115. //Valime tooted, mis vastavad 39/42
  116. //$queryID = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (76, 75, 81, 123) ORDER BY product_id DESC';
  117.  
  118. //Valime tooted, mis vastavad 43/46
  119. //$queryID = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (76, 75, 81, 123) ORDER BY product_id DESC';
  120.  
  121. //Valime tooted, mis vastavad 47/50
  122. //$queryID = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (76, 75, 81, 123) ORDER BY product_id DESC';
  123.  
  124. //Valime tooted, mis vastavad 51/54
  125. //$queryID = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (76, 75, 81, 123) ORDER BY product_id DESC';
  126.  
  127. //Valime tooted, mis vastavad 55/58
  128. //$queryID = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (76, 75, 81, 123) ORDER BY product_id DESC';
  129.  
  130. //Valime tooted, mis vastavad 59/62
  131. //$queryID = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (76, 75, 81, 123) ORDER BY product_id DESC';
  132.  
  133.  
  134. $resultID_s1 = mysqli_query($con, $queryID_s1);
  135. $resultID_s2 = mysqli_query($con, $queryID_s2);
  136. $resultID_s3 = mysqli_query($con, $queryID_s3);
  137. $resultID_s4 = mysqli_query($con, $queryID_s4);
  138. $resultID_s5 = mysqli_query($con, $queryID_s5);
  139. $resultID_s6 = mysqli_query($con, $queryID_s6);
  140. $resultID_s7 = mysqli_query($con, $queryID_s7);
  141. $resultID_s8 = mysqli_query($con, $queryID_s8);
  142. $resultID_s9 = mysqli_query($con, $queryID_s9);
  143. $resultID_s10 = mysqli_query($con, $queryID_s10);
  144. $resultID_s11 = mysqli_query($con, $queryID_s11);
  145. $resultID_s12 = mysqli_query($con, $queryID_s12);
  146. $resultID_s13 = mysqli_query($con, $queryID_s13);
  147. $resultID_s14 = mysqli_query($con, $queryID_s14);
  148.  
  149. $resultID_v1 = mysqli_query($con, $queryID_v1);
  150. $resultID_v2 = mysqli_query($con, $queryID_v2);
  151. $resultID_v3 = mysqli_query($con, $queryID_v3);
  152. $resultID_v4 = mysqli_query($con, $queryID_v4);
  153. $resultID_v5 = mysqli_query($con, $queryID_v5);
  154. $resultID_v6 = mysqli_query($con, $queryID_v6);
  155. $resultID_v7 = mysqli_query($con, $queryID_v7);
  156. $resultID_v8 = mysqli_query($con, $queryID_v8);
  157. $resultID_v9 = mysqli_query($con, $queryID_v9);
  158. $resultID_v10 = mysqli_query($con, $queryID_v10);
  159. $resultID_v11 = mysqli_query($con, $queryID_v11);
  160. $resultID_v12 = mysqli_query($con, $queryID_v12);
  161.  
  162. echo mysqli_error($con);
  163.  
  164. //////////////////////////////////////////////////
  165. //////////// S1 START ////////////////////////////
  166. //////////////////////////////////////////////////
  167.  
  168.  
  169. $xml_output_s1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  170. $xml_output_s1 .= '<root>
  171. ';
  172. $xml_output_s1 .= "<products>\n";
  173.  
  174. while ($row_s1 = mysqli_fetch_array($resultID_s1)){
  175.  
  176. // Pärime suuruste & omaduste unikaalse ID, millega pärime hiljem suuruste järgi laoseisud.
  177. //$size_option_id_s1 = mysqli_fetch_array(mysqli_query($con, 'SELECT id FROM jk2031_otp_option_value WHERE product_id = "'.$row_s1['product_id'].'"'))['id'];
  178.  
  179. // Pärime esmalt kuvatavatele toodetele juurde teisest tabelist laoseisud, et tulevikus süsteem välistaks tooteid, mis pole laos
  180. //$quantity_s1 = mysqli_fetch_array(mysqli_query($con, 'SELECT quantity FROM jk2031_otp_data WHERE otp_id = "'.$size_option_id_s1.'" AND product_id = "'.$row_s1['product_id'].'"'))['quantity'];
  181.  
  182.  
  183. // Pärime tootele ID numbri
  184. $product_id_s1 = mysqli_fetch_array(mysqli_query($con, 'SELECT product_id FROM jk2031_otp_data WHERE otp_id = "'.$row_s1['otp_id'].'"'))['product_id'];
  185.  
  186.  
  187. // Pärime esmalt toodetele juurde eestikeelsed toote nimetused
  188. $product_name_s1 = mysqli_fetch_array(mysqli_query($con, 'SELECT meta_title FROM jk2031_product_description WHERE product_id = "'.$product_id_s1.'"'))['meta_title'];
  189.  
  190. // Pärime tootega seotud suuruse ID
  191. $product_size_id = mysqli_fetch_array(mysqli_query($con, 'SELECT child_option_value_id FROM jk2031_otp_option_value WHERE product_id = "'.$product_id_s1.'"'))['child_option_value_id'];
  192.  
  193.  
  194.  
  195. //$lisaPildid = mysqli_query($con, 'SELECT child_option_value_id FROM jk2031_otp_option_value WHERE product_id = "'.$product_id_s1.'"');
  196.  
  197. $otp_Options = mysqli_query($con, 'SELECT otp_id FROM jk2031_otp_data WHERE product_id = "'.$row_s1['product_id'].'" ORDER BY otp_id ASC');
  198.  
  199. $otp_Values = mysqli_query($con, 'SELECT child_option_value_id FROM jk2031_otp_option_value WHERE product_id = "'.$row_s1['product_id'].'"');
  200.  
  201.  
  202.  
  203.  
  204.  
  205. //$queryID_s1 = 'SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (76, 75, 81, 123) ORDER BY product_id ASC ';
  206.  
  207.  
  208. $xml_output_s1 .= '<product>';
  209. $xml_output_s1 .= "\n";
  210.  
  211. $xml_output_s1 .= ' <product_id>'.$row_s1['product_id'].'</product_id>';
  212. $xml_output_s1 .= ' <opt_id>'.$row_s1['otp_id'].'</opt_id>';
  213. $xml_output_s1 .= ' <ean>'.$row_s1['model'].'</ean>';
  214. $xml_output_s1 .= ' <name>'.$row_s1['extra2'].'</name>';
  215.  
  216.  
  217. $xml_output_s1 .= '<sizes>';
  218. $xml_output_s1 .= "\n";
  219.  
  220. while($option_id = mysqli_fetch_array($otp_Options)){
  221.  
  222.  
  223. // Pärime tootega seotud suuruse nime
  224. $product_size_value = mysqli_fetch_array(mysqli_query($con, 'SELECT name FROM jk2031_option_value_description WHERE language_id = 1 AND option_value_id = "'.$option_id['child_option_value_id'].'"'))['name'];
  225.  
  226.  
  227.  
  228. // Pärida otp_id
  229. $size_otp_id = mysqli_fetch_array(mysqli_query($con, 'SELECT otp_id FROM jk2031_otp_data WHERE product_id = "'.$row_s1['product_id'].'" AND weight = "'.$product_size_value.'"'))['otp_id'];
  230.  
  231.  
  232.  
  233.  
  234. // Pärime laoseisu
  235. $product_qty = mysqli_fetch_array(mysqli_query($con, 'SELECT quantity FROM jk2031_otp_data WHERE otp_id = "'.$option_id['otp_id'].'"'))['quantity'];
  236.  
  237.  
  238. $xml_output_s1 .= '<size otp_id="'.$option_id['otp_id'].'" product_id="'.$product_id_s1.'" size_value_id="'.$option_id['child_option_value_id'].'" size_value_name="'.$product_size_value.'" qty="'.$product_qty.'">'.$product_size_value.'</size>';
  239.  
  240. }
  241.  
  242. $xml_output_s1 .= '</sizes>';
  243.  
  244.  
  245.  
  246. //$xml_output_s1 .= ' <filter_size>50/56</filter_size>';
  247. //$xml_output_s1 .= ' <filter_size_id>144</filter_size_id>';
  248. //$xml_output_s1 .= ' <filter_size_value_id>'.$size_option_id_s1.'</filter_size_value_id>';
  249.  
  250.  
  251. //$xml_output_s1 .= ' <quantity>'.$quantity_s1.'</quantity>';
  252.  
  253. $xml_output_s1 .= "\n\t</product>\n";
  254. }
  255. $xml_output_s1 .= "</products></root>";
  256.  
  257. $file_s1 = 'suurus_s1.xml';
  258. file_put_contents($file_s1, $xml_output_s1);
  259. echo $xml_output_s1;
  260.  
  261. //////////////////////////////////////////////////
  262. //////////// S1 LÕPP /////////////////////////////
  263. //////////////////////////////////////////////////
  264.  
  265.  
  266.  
  267.  
  268.  
  269. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement