Mobil visibility fix
This commit is contained in:
@@ -2,12 +2,196 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
use App\Models\CountryCode;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Client\Pool;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use PHPHtmlParser\Dom;
|
||||
|
||||
|
||||
function parseJson($json_raw, $country)
|
||||
{
|
||||
$json_values = array();
|
||||
Log::info('{json_raw} {country}', [$json_raw, $country]);
|
||||
$json_decoded = json_decode($json_raw, true);
|
||||
|
||||
$searchResultPage = $json_decoded["searchResultPage"];
|
||||
$products = $searchResultPage["products"];
|
||||
$main = $products["main"];
|
||||
$items = $main["items"];
|
||||
|
||||
foreach ($items as $item) {
|
||||
$product = $item["product"];
|
||||
|
||||
$salesPrice = $product["salesPrice"];
|
||||
$numeral = $salesPrice["numeral"];
|
||||
|
||||
$json_values = array(
|
||||
'url' => $product['pipUrl'],
|
||||
'tag' => $product['tag'],
|
||||
'country' => $country,
|
||||
'salesPrice' => $numeral,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
return $json_values;
|
||||
}
|
||||
|
||||
function parseJson_TR($body,$country)
|
||||
{
|
||||
//echo "country: " . $country . ", code: " . $code . "<br>";
|
||||
|
||||
$dochtml = new DOMDocument("1.0", "UTF-8");
|
||||
@$dochtml->loadHTML( $body);
|
||||
|
||||
@$xpath = new DOMXpath($dochtml);
|
||||
$price = null;
|
||||
//$c = ltrim($code, "0");
|
||||
$json_values = array();
|
||||
|
||||
$url_product = $xpath->query('/html/head/meta[(@property="og:url")]/@content')[0]->nodeValue;
|
||||
$price = $xpath->query('/html/head/meta[(@property="og:price:amount")]/@content')[0]->nodeValue;
|
||||
|
||||
$price = floatval(trim(str_replace('.', '', $price)));
|
||||
|
||||
$json_values = array(
|
||||
'url' => $url_product,
|
||||
'tag' => null,
|
||||
'salesPrice' => floatval($price),
|
||||
'country' => $country,
|
||||
);
|
||||
|
||||
return $json_values;
|
||||
}
|
||||
|
||||
function parseJson_CY_GR_BG($code, $body , $country)
|
||||
{
|
||||
//echo "country: " . $country . ", code: " . $code . "<br>";
|
||||
//Log::info('{country},{body},{code}',[$country, $body, $code]);
|
||||
//$body = file_get_contents("https://www.ikea.bg/search-results/?query=80366284");
|
||||
libxml_use_internal_errors(true);
|
||||
$dochtml = new DOMDocument();
|
||||
@$dochtml->loadHTML($body);
|
||||
|
||||
@$xpath = new DOMXpath($dochtml);
|
||||
$price = null;
|
||||
$c = ltrim($code, "0");
|
||||
$json_values = array();
|
||||
|
||||
@$price = $xpath->query('//*/div[(@class="yotpo yotpo-main-widget" and @data-product-id="' . $code . '")]/@data-price')[0]->nodeValue;
|
||||
@$url_product = $xpath->query('//*/div[(@class="yotpo yotpo-main-widget" and @data-product-id="' . $code . '")]/@data-url')[0]->nodeValue;
|
||||
|
||||
$price = floatval($price);
|
||||
|
||||
|
||||
$json_values = array(
|
||||
'url_product' => $url_product,
|
||||
'tag' => null,
|
||||
'salesPrice' => floatval($price),
|
||||
'country' => $country,
|
||||
);
|
||||
libxml_clear_errors();
|
||||
return $json_values;
|
||||
}
|
||||
|
||||
function parseJson_EE_LT_LV($code, $body, $country)
|
||||
{
|
||||
//echo "country: " . $country . ", code: " . $code . "<br>";
|
||||
|
||||
$dochtml = new DOMDocument("1.0", "UTF-8");
|
||||
@$dochtml->loadHTML( $body);
|
||||
|
||||
@$xpath = new DOMXpath($dochtml);
|
||||
$price = null;
|
||||
$c = ltrim($code, "0");
|
||||
$json_values = array();
|
||||
|
||||
@$price = $xpath->query('//*/div[(@class="itemPriceBox" and @data-item="' . $c . '")]//p[@class="itemNormalPrice display-6"]/span')[0]->nodeValue;
|
||||
|
||||
if (is_null($price) || empty($price)) {
|
||||
@$price = $xpath->query('//*/div[(@class="itemPriceBox" and @data-item="' . $c . '")]//div[@class="itemBTI display-6"]/span')[0]->nodeValue;
|
||||
}
|
||||
|
||||
switch ($country) {
|
||||
case "EE":
|
||||
$url_product = "https://www.ikea.ee" . $xpath->query('//*/div[(@class="card-header")]/a/@href')[0]->nodeValue;
|
||||
break;
|
||||
case "LT":
|
||||
$url_product = "https://www.ikea.lt" . $xpath->query('//*/div[(@class="card-header")]/a/@href')[0]->nodeValue;
|
||||
break;
|
||||
case "LV":
|
||||
$url_product = "https://www.ikea.lv" . $xpath->query('//*/div[(@class="card-header")]/a/@href')[0]->nodeValue;
|
||||
break;
|
||||
default:
|
||||
$url_product = null;
|
||||
}
|
||||
|
||||
if (is_null($price) || empty($price)) {
|
||||
$url_product = null;
|
||||
}
|
||||
|
||||
$price = floatval(trim(str_replace(' ', '', str_replace(',', '.', str_replace(array('€'), '', $price)))));
|
||||
|
||||
$json_values = array(
|
||||
'url' => $url_product,
|
||||
'tag' => null,
|
||||
'salesPrice' => $price,
|
||||
'country' => $country,
|
||||
);
|
||||
|
||||
return $json_values;
|
||||
}
|
||||
|
||||
function parseJson_IS($code, $body, $country)
|
||||
{
|
||||
//echo "country: " . $country . ", code: " . $code . "<br>";
|
||||
|
||||
//$body = file_get_contents("https://ikea.is/is/search/?q=80366284");
|
||||
// $client = new \GuzzleHttp\Client();
|
||||
// $res = $client->request('GET', 'https://ikea.is/is/search/?q=80366284');
|
||||
// $body= $res->getBody()->getContents();
|
||||
$dochtml = new DOMDocument("1.0", "UTF-8");
|
||||
@$dochtml->loadHTML( $body);
|
||||
|
||||
@$xpath = new DOMXpath($dochtml);
|
||||
$price = null;
|
||||
$c = ltrim($code, "0");
|
||||
$json_values = array();
|
||||
|
||||
// try {
|
||||
@$price = $xpath->query('//*/div[(@class="itemPriceBox")]//p[@class="itemNormalPrice revamp_price price"]/span/span')[0]->nodeValue;
|
||||
|
||||
if (is_null($price) || empty($price)) {
|
||||
@$price = $xpath->query('//*/div[(@class="itemPriceBox")]//p[@class="itemBTI display-6 revamp_price price"]/span/span')[0]->nodeValue;
|
||||
}
|
||||
|
||||
@$url_product = "https://www.ikea.is" . $xpath->query('/html/head/meta[(@property="og:url")]/@content')[0]->nodeValue;
|
||||
|
||||
//echo "url_product: " . $url_product . "<br>";
|
||||
|
||||
if (is_null($price) || empty($price)) {
|
||||
$url_product = null;
|
||||
}
|
||||
|
||||
//} catch (\Exception $e) {
|
||||
// return [];
|
||||
//}
|
||||
$price = floatval(trim(str_replace(' ', '', str_replace(',', '.', str_replace('.', '', str_replace(array('€'), '', $price))))));
|
||||
|
||||
$json_values = array(
|
||||
'url' => $url_product,
|
||||
'tag' => null,
|
||||
'salesPrice' => $price,
|
||||
'country' => $country,
|
||||
);
|
||||
|
||||
return $json_values;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class CountryCompareController extends Controller
|
||||
{
|
||||
@@ -75,21 +259,21 @@ class CountryCompareController extends Controller
|
||||
case "BG":
|
||||
case "CY":
|
||||
case "GR":
|
||||
$prices[$country] = $this->parseJson_CY_GR_BG($code, (string) $response, $country);
|
||||
$prices[$country] = parseJson_CY_GR_BG($code, (string) $response, $country);
|
||||
break;
|
||||
case "IS":
|
||||
$prices[$country] = $this->parseJson_IS($code,(string) $response, $country);
|
||||
$prices[$country] = parseJson_IS($code,(string) $response, $country);
|
||||
break;
|
||||
case "TR":
|
||||
$prices[$country] = $this->parseJson_TR((string) $response, $country);
|
||||
$prices[$country] = parseJson_TR((string) $response, $country);
|
||||
break;
|
||||
case "EE":
|
||||
case "LT":
|
||||
case "LV":
|
||||
$prices[$country] = $this->parseJson_EE_LT_LV($code, (string) $response, $country);
|
||||
$prices[$country] = parseJson_EE_LT_LV($code, (string) $response, $country);
|
||||
break;
|
||||
default:
|
||||
$prices[$country] = $this->parseJson((string) $response, $country);
|
||||
$prices[$country] = parseJson((string) $response, $country);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,186 +285,5 @@ class CountryCompareController extends Controller
|
||||
});
|
||||
return collect($products);
|
||||
}
|
||||
|
||||
// { "country": "AT", "code": "50161321", "url": "https://www.ikea.com/at/de/p/hol-aufbewahrungstisch-akazie-50161321/", "name": "HOL", "typeName": "Aufbewahrungstisch", "mainImageUrl": "https://www.ikea.com/at/de/images/products/hol-aufbewahrungstisch-akazie__0104310_pe251255_s5.jpg", "itemNoGlobal": "50161321", "salesPrice": "80.99", "tag": "FAMILY_PRICE", "last_mod": "2023-12-03 16:44:24" },
|
||||
|
||||
public function parseJson($json_raw, $country)
|
||||
{
|
||||
$json_values = array();
|
||||
Log::info('{json_raw} {country}', [$json_raw, $country]);
|
||||
$json_decoded = json_decode($json_raw, true);
|
||||
|
||||
$searchResultPage = $json_decoded["searchResultPage"];
|
||||
$products = $searchResultPage["products"];
|
||||
$main = $products["main"];
|
||||
$items = $main["items"];
|
||||
|
||||
foreach ($items as $item) {
|
||||
$product = $item["product"];
|
||||
|
||||
$salesPrice = $product["salesPrice"];
|
||||
$numeral = $salesPrice["numeral"];
|
||||
|
||||
$json_values = array(
|
||||
'url' => $product['pipUrl'],
|
||||
'tag' => $product['tag'],
|
||||
'country' => $country,
|
||||
'salesPrice' => $numeral,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
return $json_values;
|
||||
}
|
||||
|
||||
public function parseJson_TR($body,$country)
|
||||
{
|
||||
//echo "country: " . $country . ", code: " . $code . "<br>";
|
||||
|
||||
$dochtml = new \DOMDocument();
|
||||
@$dochtml->loadHTML( $body);
|
||||
|
||||
@$xpath = new \DOMXpath($dochtml);
|
||||
$price = null;
|
||||
//$c = ltrim($code, "0");
|
||||
$json_values = array();
|
||||
|
||||
$url_product = $xpath->query('/html/head/meta[(@property="og:url")]/@content')[0]->nodeValue;
|
||||
$price = $xpath->query('/html/head/meta[(@property="og:price:amount")]/@content')[0]->nodeValue;
|
||||
|
||||
$price = floatval(trim(str_replace('.', '', $price)));
|
||||
|
||||
$json_values = array(
|
||||
'url' => $url_product,
|
||||
'tag' => null,
|
||||
'salesPrice' => floatval($price),
|
||||
'country' => $country,
|
||||
);
|
||||
|
||||
return $json_values;
|
||||
}
|
||||
|
||||
public function parseJson_CY_GR_BG($code, $body , $country)
|
||||
{
|
||||
//echo "country: " . $country . ", code: " . $code . "<br>";
|
||||
//Log::info('{country},{body},{code}',[$country, $body, $code]);
|
||||
//$body = file_get_contents("https://www.ikea.bg/search-results/?query=80366284");
|
||||
|
||||
$dochtml = new \DOMDocument();
|
||||
@$dochtml->loadHTML($body);
|
||||
|
||||
@$xpath = new \DOMXpath($dochtml);
|
||||
$price = null;
|
||||
$c = ltrim($code, "0");
|
||||
$json_values = array();
|
||||
|
||||
@$price = $xpath->query('//*/div[(@class="yotpo yotpo-main-widget" and @data-product-id="' . $code . '")]/@data-price')[0]->nodeValue;
|
||||
@$url_product = $xpath->query('//*/div[(@class="yotpo yotpo-main-widget" and @data-product-id="' . $code . '")]/@data-url')[0]->nodeValue;
|
||||
|
||||
$price = floatval($price);
|
||||
|
||||
|
||||
$json_values = array(
|
||||
'url_product' => $url_product,
|
||||
'tag' => null,
|
||||
'salesPrice' => floatval($price),
|
||||
'country' => $country,
|
||||
);
|
||||
|
||||
return $json_values;
|
||||
}
|
||||
|
||||
public function parseJson_EE_LT_LV($code, $body, $country)
|
||||
{
|
||||
//echo "country: " . $country . ", code: " . $code . "<br>";
|
||||
|
||||
$dochtml = new \DOMDocument();
|
||||
@$dochtml->loadHTML( $body);
|
||||
|
||||
@$xpath = new \DOMXpath($dochtml);
|
||||
$price = null;
|
||||
$c = ltrim($code, "0");
|
||||
$json_values = array();
|
||||
|
||||
@$price = $xpath->query('//*/div[(@class="itemPriceBox" and @data-item="' . $c . '")]//p[@class="itemNormalPrice display-6"]/span')[0]->nodeValue;
|
||||
|
||||
if (is_null($price) || empty($price)) {
|
||||
@$price = $xpath->query('//*/div[(@class="itemPriceBox" and @data-item="' . $c . '")]//div[@class="itemBTI display-6"]/span')[0]->nodeValue;
|
||||
}
|
||||
|
||||
switch ($country) {
|
||||
case "EE":
|
||||
$url_product = "https://www.ikea.ee" . $xpath->query('//*/div[(@class="card-header")]/a/@href')[0]->nodeValue;
|
||||
break;
|
||||
case "LT":
|
||||
$url_product = "https://www.ikea.lt" . $xpath->query('//*/div[(@class="card-header")]/a/@href')[0]->nodeValue;
|
||||
break;
|
||||
case "LV":
|
||||
$url_product = "https://www.ikea.lv" . $xpath->query('//*/div[(@class="card-header")]/a/@href')[0]->nodeValue;
|
||||
break;
|
||||
default:
|
||||
$url_product = null;
|
||||
}
|
||||
|
||||
if (is_null($price) || empty($price)) {
|
||||
$url_product = null;
|
||||
}
|
||||
|
||||
$price = floatval(trim(str_replace(' ', '', str_replace(',', '.', str_replace(array('€'), '', $price)))));
|
||||
|
||||
$json_values = array(
|
||||
'url' => $url_product,
|
||||
'tag' => null,
|
||||
'salesPrice' => $price,
|
||||
'country' => $country,
|
||||
);
|
||||
|
||||
return $json_values;
|
||||
}
|
||||
|
||||
public function parseJson_IS($code, $body, $country)
|
||||
{
|
||||
//echo "country: " . $country . ", code: " . $code . "<br>";
|
||||
|
||||
//$body = file_get_contents("https://ikea.is/is/search/?q=80366284");
|
||||
// $client = new \GuzzleHttp\Client();
|
||||
// $res = $client->request('GET', 'https://ikea.is/is/search/?q=80366284');
|
||||
// $body= $res->getBody()->getContents();
|
||||
$dochtml = new \DOMDocument();
|
||||
@$dochtml->loadHTML( $body);
|
||||
|
||||
@$xpath = new \DOMXpath($dochtml);
|
||||
$price = null;
|
||||
$c = ltrim($code, "0");
|
||||
$json_values = array();
|
||||
|
||||
// try {
|
||||
@$price = $xpath->query('//*/div[(@class="itemPriceBox")]//p[@class="itemNormalPrice revamp_price price"]/span/span')[0]->nodeValue;
|
||||
|
||||
if (is_null($price) || empty($price)) {
|
||||
@$price = $xpath->query('//*/div[(@class="itemPriceBox")]//p[@class="itemBTI display-6 revamp_price price"]/span/span')[0]->nodeValue;
|
||||
}
|
||||
|
||||
@$url_product = "https://www.ikea.is" . $xpath->query('/html/head/meta[(@property="og:url")]/@content')[0]->nodeValue;
|
||||
|
||||
//echo "url_product: " . $url_product . "<br>";
|
||||
|
||||
if (is_null($price) || empty($price)) {
|
||||
$url_product = null;
|
||||
}
|
||||
|
||||
//} catch (\Exception $e) {
|
||||
// return [];
|
||||
//}
|
||||
$price = floatval(trim(str_replace(' ', '', str_replace(',', '.', str_replace('.', '', str_replace(array('€'), '', $price))))));
|
||||
|
||||
$json_values = array(
|
||||
'url' => $url_product,
|
||||
'tag' => null,
|
||||
'salesPrice' => $price,
|
||||
'country' => $country,
|
||||
);
|
||||
|
||||
return $json_values;
|
||||
}
|
||||
}
|
||||
// { "country": "AT", "code": "50161321", "url": "https://www.ikea.com/at/de/p/hol-aufbewahrungstisch-akazie-50161321/", "name": "HOL", "typeName": "Aufbewahrungstisch", "mainImageUrl": "https://www.ikea.com/at/de/images/products/hol-aufbewahrungstisch-akazie__0104310_pe251255_s5.jpg", "itemNoGlobal": "50161321", "salesPrice": "80.99", "tag": "FAMILY_PRICE", "last_mod": "2023-12-03 16:44:24" },
|
||||
|
||||
Reference in New Issue
Block a user