Browse Source

Update Data Stop API

docjyJ 1 year ago
parent
commit
2786d17e5d
1 changed files with 7 additions and 21 deletions
  1. 7
    21
      classes/postHandler.php

+ 7
- 21
classes/postHandler.php View File

@@ -84,27 +84,13 @@ class PostHandler
84 84
         foreach ($articles as $article) {
85 85
             $article["type"] = $this->dao->get_categories_of_article($article["id"]);
86 86
             //EXPERIMENTAL
87
-            $response = $this->get_openfoodfacts_product('3057640385148');
88
-            if($response["status"] == 1){
89
-                $product = $response["product"];
90
-                $article["image_"] = $product["image_front_url"] != "" ? $product["image_front_url"] : $this->imageBaseUrl . $article["id"] . ".jpg";;
91
-                $article["nutri_score"] = $product["nutrition_grade_fr"];
92
-                $article["ingredients_fr"] = $product["ingredients_text_fr"] != "" ? $product["ingredients_text_fr"] : $product["ingredients_text"];
93
-                $article["ingredients_en"] = $product["ingredients_text_en"] != "" ? $product["ingredients_text_en"] : $product["ingredients_text"];
94
-                $article["name_fr"] = $product["product_name_fr"] != "" ? $product["product_name_fr"] : $product["product_name"];
95
-                $article["name_en"] = $product["product_name_en"] != "" ? $product["product_name_en"] : $product["product_name"];
96
-                $article["description_fr"] = $product["generic_name_fr"] != "" ? $product["generic_name_fr"] : $product["generic_name"];
97
-                $article["description_en"] = $product["generic_name_en"] != "" ? $product["generic_name_en"] : $product["generic_name"];
98
-            } else {
99
-                $article["image"] = $this->imageBaseUrl . $article["id"] . ".jpg";
100
-                $article["nutri_score"] = "";
101
-                $article["ingredients_fr"] = "";
102
-                $article["ingredients_en"] = "";
103
-                $article["name_fr"] = "";
104
-                $article["name_en"] = "";
105
-                $article["description_fr"] = "";
106
-                $article["description_en"] = "";
107
-            }
87
+            $response = $this->get_openfoodfacts_product($article["code"]);
88
+            $product = $response["product"];
89
+            $article["image"] = $product["image_front_url"] != "" ? $product["image_front_url"] : $this->imageBaseUrl . $article["id"] . ".jpg";
90
+            $article["nutri-score"] = !empty($product["nutrition_grade_fr"])  ? $product["nutrition_grade_fr"]  : null;
91
+            $article["ingredients"] = !empty($product["ingredients_text_fr"]) ? $product["ingredients_text_fr"] : !empty($product["ingredients_text"]) ? $product["ingredients_text"] : null;
92
+            $article["name"]        = !empty($product["product_name_fr"])     ? $product["product_name_fr"]     : !empty($product["product_name"])     ? $product["product_name"]     : $article["name"];
93
+            $article["description"] = !empty($product["generic_name_fr"])     ? $product["generic_name_fr"]     : !empty($product["generic_name"])     ? $product["generic_name"]     : $article["description"];
108 94
             array_push($formatted_articles, $article);
109 95
         }
110 96
 

Loading…
Cancel
Save