From c502f47f236778c149420a8e3615be8b14a41856 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Phil=20H=C3=B6fer?= <phil@suma-ev.de>
Date: Wed, 6 Mar 2019 10:40:20 +0100
Subject: [PATCH] Add new product search demo

---
 ProdSearch.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 ProdSearch.php

diff --git a/ProdSearch.php b/ProdSearch.php
new file mode 100644
index 000000000..b4d5381e8
--- /dev/null
+++ b/ProdSearch.php
@@ -0,0 +1,52 @@
+<?php
+
+namespace app\Models\parserSkripte;
+
+use App\Models\Searchengine;
+
+class ProdSearch extends Searchengine
+{
+    public $results = [];
+
+    public function __construct($name, \StdClass $engine, \App\MetaGer $metager)
+    {
+        parent::__construct($name, $engine, $metager);
+    }
+
+    public function loadResults($result)
+    {
+        $results = json_decode($result, true);
+        foreach ($results as $result) {
+            if ($this->counter >= 10) {
+                break;
+            }
+
+            $title       = $result["title"];
+            $link        = $result["product-link"];
+            $anzeigeLink = $link;
+            $price       = 0;
+            $descr       = "";
+            if (isset($result['price_cents'])) {
+                $price = intval($result['price_cents']);
+                $descr .= "<p>Preis: " . (intval($result['price_cents']) / 100.0) . " €</p>";
+            }
+            if (isset($result['image-url'])) {
+                $image = $result['image-url'];
+            }
+
+            $this->counter++;
+            $this->results[] = new \App\Models\Result(
+                $this->engine,
+                $title,
+                $link,
+                $anzeigeLink,
+                $descr,
+                $this->engine->{"display-name"},$this->engine->homepage,
+                $this->counter,
+                [
+                    'price' => $price,
+                    'image' => $image]
+            );
+        }
+    }
+}
-- 
GitLab