Ebay.php 2.51 KB
Newer Older
1
2
3
<?php

namespace app\Models\parserSkripte;
4

5
use App\Models\Searchengine;
Phil Höfer's avatar
Phil Höfer committed
6
use Log;
7

8
class Ebay extends Searchengine
9
{
10
11
    public $results = [];

Dominik Hebeler's avatar
Dominik Hebeler committed
12
    public function __construct($name, \stdClass $engine, \App\MetaGer $metager)
13
    {
Dominik Hebeler's avatar
Dominik Hebeler committed
14
        parent::__construct($name, $engine, $metager);
15
16
17
18
    }

    public function loadResults($result)
    {
19
        $result = preg_replace("/\r\n/si", "", $result);
20
        try {
Dominik Hebeler's avatar
Dominik Hebeler committed
21
            $content = \simplexml_load_string($result);
22
23
            if (!$content) {
                return;
24
25
            }

26
            $results = $content->{"searchResult"};
Dominik Hebeler's avatar
Dominik Hebeler committed
27
            $count = 0;
28
            foreach ($results->{"item"} as $result) {
Dominik Hebeler's avatar
Dominik Hebeler committed
29
30
                $title = $result->{"title"}->__toString();
                $link = $result->{"viewItemURL"}->__toString();
31
                $anzeigeLink = $link;
Dominik Hebeler's avatar
Dominik Hebeler committed
32
33
34
35
                $time = $result->{"listingInfo"}->{"endTime"}->__toString();
                $time = date(DATE_RFC2822, strtotime($time));
                $price = intval($result->{"sellingStatus"}->{"convertedCurrentPrice"}->__toString()) * 100;
                $descr = "Preis: " . $result->{"sellingStatus"}->{"convertedCurrentPrice"}->__toString() . " €";
36
                $descr .= ", Versandkosten: " . $result->{"shippingInfo"}->{"shippingServiceCost"}->__toString() . " €";
37
                if (isset($result->{"listingInfo"}->{"listingType"})) {
38
                    $descr .= ", Auktionsart: " . $result->{"listingInfo"}->{"listingType"}->__toString();
39
                }
40

41
                $descr .= ", Auktionsende: " . $time;
42
                if (isset($result->{"primaryCategory"}->{"categoryName"})) {
43
                    $descr .= ", Kategorie: " . $result->{"primaryCategory"}->{"categoryName"}->__toString();
44
                }
45

46
47
48
49
50
51
52
53
                $image = $result->{"galleryURL"}->__toString();
                $this->counter++;
                $this->results[] = new \App\Models\Result(
                    $this->engine,
                    $title,
                    $link,
                    $anzeigeLink,
                    $descr,
Dominik Hebeler's avatar
Dominik Hebeler committed
54
                    $this->engine->{"display-name"}, $this->engine->homepage,
55
                    $this->counter,
56
                    ['partnershop' => false,
Dominik Hebeler's avatar
Dominik Hebeler committed
57
58
                        'price' => $price,
                        'image' => $image]
59
60
61
62
                );
                $count++;
            }
        } catch (\Exception $e) {
63
64
            Log::error("A problem occurred parsing results from $this->name:");
            Log::error($e->getMessage());
65
            return;
66
67
68
        }
    }
}