Commit bdbf4b8b authored by Dominik Hebeler's avatar Dominik Hebeler

Merge branch '875-add-kelkoo-product-search' into 'development'

Resolve "Add Kelkoo product search"

Closes #875

See merge request !1422
parents 6cc7dbd9 d8d9ed2d
......@@ -35,6 +35,7 @@ class Result
# Erstellt ein neues Ergebnis
public function __construct($provider, $titel, $link, $anzeigeLink, $descr, $gefVon, $gefVonLink, $sourceRank, $additionalInformation = [])
{
$this->provider = $provider;
$this->titel = strip_tags(trim($titel));
$this->link = trim($link);
$this->anzeigeLink = trim($anzeigeLink);
......@@ -278,7 +279,27 @@ class Result
/* Der Dublettenfilter, der sicher stellt,
* dass wir nach Möglichkeit keinen Link doppelt in der Ergebnisliste haben.
*/
if ($metager->addLink($this->strippedLink)) {
$dublettenLink = $this->strippedLink;
if (!empty($this->provider->{"dubletten-include-parameter"}) && sizeof($this->provider->{"dubletten-include-parameter"}) > 0) {
$dublettenLink .= "?";
$query = parse_url($this->link);
if (!empty($query["query"])) {
$queryTmp = explode("&", $query["query"]);
$query = [];
foreach ($queryTmp as $getParameter) {
$keyVal = explode("=", $getParameter);
$query[$keyVal[0]] = $keyVal[1];
}
foreach ($this->provider->{"dubletten-include-parameter"} as $param) {
if (!empty($query[$param])) {
$dublettenLink .= $param . "=" . $query[$param] . "&";
}
}
$dublettenLink = rtrim($dublettenLink, "&");
}
}
if ($metager->addLink($dublettenLink)) {
$metager->addHostCount($this->strippedHost);
return true;
} else {
......
<?php
namespace app\Models\parserSkripte;
use App\Models\Searchengine;
use Log;
class Kelkoo extends Searchengine
{
public $results = [];
public $unsignedGetString = "";
public function __construct($name, \StdClass $engine, \App\MetaGer $metager)
{
parent::__construct($name, $engine, $metager);
$this->unsignedGetString = $this->getString;
$this->getString = $this->UrlSigner($this->unsignedGetString);
$this->hash = md5($this->engine->host . $this->getString . $this->engine->port . $this->name);
}
public function loadResults($result)
{
$result = preg_replace("/\r\n/si", "", $result);
# delete namespace, allowing easier xpath access
$result = str_replace('xmlns="urn:yahoo:prods"', '', $result);
try {
$content = simplexml_load_string($result);
if (!$content) {
return;
}
# Kekloo gives us the total Result Count
$resultCount = $content->xpath('/ProductSearch/Products/@totalResultsAvailable');
if (sizeof($resultCount) > 0) {
$resultCount = intval($resultCount[0]->__toString());
} else {
$resultCount = 0;
}
$this->totalResults = $resultCount;
$results = $content->xpath('/ProductSearch/Products/Product/Offer');
foreach ($results as $result) {
$result = simplexml_load_string($result->saveXML());
$title = $result->Title[0]->__toString();
$price = floatval($result->Price[0]->Price[0]);
$deliveryPrice = floatval($result->Price[0]->DeliveryCost[0]);
$totalPrice = $price + $deliveryPrice;
$descr = "";
if(isset($result->Description[0]))
{
$descr = $result->Description[0]->__toString();
}
$descr .= "<p>Preis: " . $price . " €</p>";
$image = $result->Images[0]->Image[0]->Url[0]->__toString();
$link = $result->Url[0]->__toString();
$anzeigeLink = $result->Merchant[0]->Name[0]->__toString();
$this->counter++;
$this->results[] = new \App\Models\Result(
$this->engine,
$title,
$link,
$anzeigeLink,
$descr,
$this->engine->{"display-name"},$this->engine->homepage,
$this->counter,
['image' => $image,
'price' => $totalPrice * 100]
);
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name:");
Log::error($e->getMessage());
return;
}
}
public function getNext(\App\MetaGer $metager, $result)
{
$result = preg_replace("/\r\n/si", "", $result);
# delete namespace, allowing easier xpath access
$result = str_replace('xmlns="urn:yahoo:prods"', '', $result);
try {
$content = simplexml_load_string($result);
if (!$content) {
return;
}
} catch (\Exception $e) {
Log::error("A problem occurred parsing results from $this->name:");
Log::error($e->getMessage());
return;
}
# Kekloo gives us the total Result Count
$resultCount = $content->xpath('/ProductSearch/Products/@totalResultsAvailable');
if (sizeof($resultCount) > 0) {
$resultCount = intval($resultCount[0]->__toString());
} else {
$resultCount = 0;
}
$this->totalResults = $resultCount;
// Get the current Result Position
$current = 0;
if (strpos($this->getString, "&start=") !== false) {
$tmp = substr($this->getString, strpos($this->getString, "&start=") + 7);
if (strpos($tmp, "&") !== false) {
$tmp = substr($tmp, 0, strpos($tmp, "&"));
}
$current = intval($tmp);
}
if ($current >= ($this->totalResults - 20)) {
return;
}
# Erstellen des neuen Suchmaschinenobjekts und anpassen des GetStrings:
$next = new Kelkoo($this->name, $this->engine, $metager);
$next->unsignedGetString .= "&start=" . ($current + 20);
$next->getString = $next->UrlSigner($next->unsignedGetString);
$next->hash = md5($next->engine->host . $next->getString . $next->engine->port . $next->name);
$this->next = $next;
}
# kelkoogroup.com/kelkoo-customer-service/kelkoo-developer-network/shopping-services/samples/signing-url-php/
public function UrlSigner($path){
$urlPath = $path;
$partner = $this->engine->{"http-auth-credentials"}->ID;
$key = $this->engine->{"http-auth-credentials"}->Key;
$URL_sig = "hash";
$URL_ts = "timestamp";
$URL_partner = "aid";
$URLreturn = "";
$URLtmp = "";
$s = "";
// get the timestamp
$time = time();
// replace " " by "+"
$urlPath = str_replace(" ", "+", $urlPath);
// format URL
$URLtmp = $urlPath . "&" . $URL_partner . "=" . $partner . "&" . $URL_ts . "=" . $time;
// URL needed to create the token
$s = $urlPath . "&" . $URL_partner . "=" . $partner . "&" . $URL_ts . "=" . $time . $key;
$token = "";
$token = base64_encode(pack('H*', md5($s)));
$token = str_replace(array("+", "/", "="), array(".", "_", "-"), $token);
$URLreturn = $URLtmp . "&" . $URL_sig . "=" . $token;
return $URLreturn;
}
}
......@@ -32,7 +32,7 @@ class Mg_produkt2 extends Searchengine
$link = $result->xpath('/doc/arr[@name="artikelDeeplink"]')[0]->{"str"}->__toString();
$anzeigeLink = parse_url($link);
parse_str($anzeigeLink['query'], $query);
$anzeigeLink = $query['url'];
$anzeigeLink = $query['diurl'];
$descr = $result->xpath('/doc/arr[@name="artikelBeschreibung"]')[0]->{"str"}->__toString();
$image = $result->xpath('/doc/arr[@name="artikelImageurl"]')[0]->{"str"}->__toString();
$this->counter++;
......
......@@ -122,5 +122,13 @@ return [
"filter.market.cc" => "Chinesisch (China)",
"filter.market.ct" => "Chinesisch (Taiwan)",
"filter.sort" => "Sortieren nach",
"filter.sort.priceascending" => "Preis (aufsteigend)",
"filter.sort.pricedescending" => "Preis (absteigend)",
"filter.sort.totalpriceascending" => "Gesamtpreis (aufsteigend)",
"filter.sort.totalpricedescending" => "Gesamtpreis (absteigend)",
"filter.rabate" => "Min. Rabatt",
"settings" => "Einstellungen",
];
......@@ -122,5 +122,13 @@ return [
"filter.market.cc" => "Chinese (China)",
"filter.market.ct" => "Chinese (Taiwan)",
"filter.sort" => "Sort By",
"filter.sort.priceascending" => "Price (ascending)",
"filter.sort.pricedescending" => "Price (descending)",
"filter.sort.totalpriceascending" => "Total Price (ascending)",
"filter.sort.totalpricedescending" => "Total Price (descending)",
"filter.rabate" => "Min. Rabate",
"settings" => "Settings",
];
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment