Advertisement
nicolaslagios

cateogory tree prestashop product

Jul 7th, 2022 (edited)
1,042
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.09 KB | None | 0 0
  1. <?php
  2.  
  3. $conn = new mysqli("localhost", "name", "password", "name"); //edw mpainoun ta stoixeia ths bashs
  4.  
  5. /* ------------------------------ ΣΥΝΑΡΤΗΣΗ ΔΕΝΤΡΟΥ ΚΑΤΗΓΟΡΙΩΝ ------------------ΑΡΧΗ--------- */
  6. function dentrokathgorias ($proion_id, $glwssa_id) {
  7. global $conn;
  8. $kathgoria_step1 = $conn->query("SELECT id_category FROM ps_category_product WHERE id_product = ".$proion_id.";"); //id kathgoriwn me bash to id product
  9. $kathgoria_step1_array = array();
  10. $kathgoria_step2_array = array(); //einai to array mesa sto loop
  11. while($r1 = mysqli_fetch_assoc($kathgoria_step1)) {$kathgoria_step1_array[] = $r1;}
  12. $ki = 0;
  13. while($ki < count($kathgoria_step1_array)){
  14.     $kathgoria_step2 = $conn->query("SELECT level_depth FROM ps_category WHERE id_category = ".$kathgoria_step1_array[$ki]['id_category'].";");
  15.     $vathos = $kathgoria_step2->fetch_object()->level_depth; //level kathgorias
  16.    
  17.     if ($vathos == 4){ //ektypwse to name ths giagias kathgorias + to name ths mamas + to name tou paidiou
  18.        
  19.         //id mamas
  20.         $kathgoria_step3a = $conn->query("SELECT id_parent FROM ps_category WHERE id_category = ".$kathgoria_step1_array[$ki]['id_category'].";");
  21.         $kathgoria_step3a_id = $kathgoria_step3a->fetch_object()->id_parent;
  22.        
  23.         //id giagias
  24.         $kathgoria_step3b = $conn->query("SELECT id_parent FROM ps_category WHERE id_category = ".$kathgoria_step3a_id.";");
  25.         $kathgoria_step3b_id = $kathgoria_step3b->fetch_object()->id_parent;
  26.        
  27.         //onoma mamas
  28.         $kathgoria_step4a = $conn->query("SELECT ps_category_lang.name FROM ps_category_lang,ps_category WHERE ps_category_lang.id_category = ".$kathgoria_step3a_id." AND ps_category_lang.id_lang = ".$glwssa_id.";");
  29.         $kathgoria_step4a_name = $kathgoria_step4a->fetch_object()->name;
  30.        
  31.         //onoma giagias
  32.         $kathgoria_step4b = $conn->query("SELECT ps_category_lang.name FROM ps_category_lang,ps_category WHERE ps_category_lang.id_category = ".$kathgoria_step3b_id." AND ps_category_lang.id_lang = ".$glwssa_id.";");
  33.         $kathgoria_step4b_name = $kathgoria_step4b->fetch_object()->name;
  34.        
  35.         //onoma paidiou
  36.         $kathgoria_step5first = $conn->query("SELECT name FROM ps_category_lang WHERE id_category = ".$kathgoria_step1_array[$ki]['id_category']." AND id_lang = ".$glwssa_id.";");
  37.         $kathgoria_step5first_name = $kathgoria_step5first->fetch_object()->name;
  38.        
  39.         //teliko apotelesma
  40.         $kathgoriesdentro[] = $kathgoria_step4b_name.">".$kathgoria_step4a_name.">".$kathgoria_step5first_name;
  41.     }
  42.     elseif ($vathos == 3){ //ektypwse to name ths mamas kathgorias + to name tou paidiou
  43.         //id mamas
  44.         $kathgoria_step3 = $conn->query("SELECT id_parent FROM ps_category WHERE id_category = ".$kathgoria_step1_array[$ki]['id_category'].";");
  45.         $kathgoria_step3_id = $kathgoria_step3->fetch_object()->id_parent;
  46.        
  47.         //onoma mamas
  48.         $kathgoria_step4 = $conn->query("SELECT ps_category_lang.name FROM ps_category_lang,ps_category WHERE ps_category_lang.id_category = ".$kathgoria_step3_id." AND ps_category_lang.id_lang = ".$glwssa_id.";");
  49.         $kathgoria_step4_name = $kathgoria_step4->fetch_object()->name;
  50.        
  51.         //onoma paidiou
  52.         $kathgoria_step5 = $conn->query("SELECT name FROM ps_category_lang WHERE id_category = ".$kathgoria_step1_array[$ki]['id_category']." AND id_lang = ".$glwssa_id.";");
  53.         $kathgoria_step5_name = $kathgoria_step5->fetch_object()->name;
  54.        
  55.         //teliko apotelesma
  56.         $kathgoriesdentro[] = $kathgoria_step4_name.">".$kathgoria_step5_name;
  57.     }
  58.     else { //ektypwse thn monh kathgoria
  59.         $kathgoria_step3else = $conn->query("SELECT name FROM ps_category_lang WHERE id_category = ".$kathgoria_step1_array[$ki]['id_category']." AND id_lang = ".$glwssa_id.";");
  60.         $kathgoria_step3else_name = $kathgoria_step3else->fetch_object()->name;
  61.         $kathgoriesdentro[] = $kathgoria_step3else_name;
  62.     }
  63.     $ki++;
  64. }
  65.     echo str_replace(' |', '|', implode("|", $kathgoriesdentro));
  66.     $kathgoriesdentro = array(); // adeiasma tou array dentrou
  67. }
  68. /* ------------------------------ ΣΥΝΑΡΤΗΣΗ ΔΕΝΤΡΟΥ ΚΑΤΗΓΟΡΙΩΝ ------------------ΤΕΛΟΣ--------- */
  69.  
  70. dentrokathgorias(2411,8); //orismata: id proiontos , id glwssas (ellhnika = 8 , agglika = 1)
  71.  
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement