Ebay.php 2.58 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
12
13
14
15
16
17
18
    public $results = [];

    public function __construct(\SimpleXMLElement $engine, \App\MetaGer $metager)
    {
        parent::__construct($engine, $metager);
    }

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

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

41
42
43
44
                $descr .= "<p>Auktionsende: " . $time . "</p>";
                if (isset($result->{"primaryCategory"}->{"categoryName"})) {
                    $descr .= "<p class=\"text-muted\">Kategorie: " . $result->{"primaryCategory"}->{"categoryName"}->__toString() . "</p>";
                }
45

46
47
48
49
50
51
52
53
54
55
                $image = $result->{"galleryURL"}->__toString();
                $this->counter++;
                $this->results[] = new \App\Models\Result(
                    $this->engine,
                    $title,
                    $link,
                    $anzeigeLink,
                    $descr,
                    $this->gefVon,
                    $this->counter,
56
57
58
                    ['partnershop' => false,
                        '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
        }
    }
}