diff --git a/app/Http/Controllers/CountryCompareController.php b/app/Http/Controllers/CountryCompareController.php index a538bed..0b63027 100644 --- a/app/Http/Controllers/CountryCompareController.php +++ b/app/Http/Controllers/CountryCompareController.php @@ -73,7 +73,7 @@ class CountryCompareController extends Controller //dd($response) switch ($country) { case "BG": - case "BY": + case "CY": case "GR": $prices[$country] = $this->parseJson_CY_GR_BG($code, (string) $response, $country); break; @@ -107,9 +107,9 @@ class CountryCompareController extends Controller public function parseJson($json_raw, $country) { $json_values = array(); - + Log::info('{json_raw} {country}', [$json_raw, $country]); $json_decoded = json_decode($json_raw, true); - //dd($json_decoded); + $searchResultPage = $json_decoded["searchResultPage"]; $products = $searchResultPage["products"]; $main = $products["main"]; @@ -138,9 +138,9 @@ class CountryCompareController extends Controller //echo "country: " . $country . ", code: " . $code . "
"; $dochtml = new \DOMDocument(); - @$dochtml->loadHTML('' . $body); + @$dochtml->loadHTML( $body); - $xpath = new \DOMXpath($dochtml); + @$xpath = new \DOMXpath($dochtml); $price = null; //$c = ltrim($code, "0"); $json_values = array(); @@ -153,7 +153,7 @@ class CountryCompareController extends Controller $json_values = array( 'url' => $url_product, 'tag' => null, - 'price' => floatval($price), + 'salesPrice' => floatval($price), 'country' => $country, ); @@ -164,18 +164,18 @@ class CountryCompareController extends Controller { //echo "country: " . $country . ", code: " . $code . "
"; //Log::info('{country},{body},{code}',[$country, $body, $code]); - $body = file_get_contents("https://www.ikea.bg/search-results/?query=80366284"); + //$body = file_get_contents("https://www.ikea.bg/search-results/?query=80366284"); $dochtml = new \DOMDocument(); - $dochtml->loadHTML($body); + @$dochtml->loadHTML($body); - $xpath = new \DOMXpath($dochtml); + @$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 = $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); @@ -183,8 +183,8 @@ class CountryCompareController extends Controller $json_values = array( 'url_product' => $url_product, 'tag' => null, - 'price' => floatval($price), - 'price_eur' => 0 + 'salesPrice' => floatval($price), + 'country' => $country, ); return $json_values; @@ -195,17 +195,17 @@ class CountryCompareController extends Controller //echo "country: " . $country . ", code: " . $code . "
"; $dochtml = new \DOMDocument(); - @$dochtml->loadHTML('' . $body); + @$dochtml->loadHTML( $body); - $xpath = new \DOMXpath($dochtml); + @$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; + @$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; + @$price = $xpath->query('//*/div[(@class="itemPriceBox" and @data-item="' . $c . '")]//div[@class="itemBTI display-6"]/span')[0]->nodeValue; } switch ($country) { @@ -231,7 +231,7 @@ class CountryCompareController extends Controller $json_values = array( 'url' => $url_product, 'tag' => null, - 'price' => $price, + 'salesPrice' => $price, 'country' => $country, ); @@ -247,21 +247,21 @@ class CountryCompareController extends Controller // $res = $client->request('GET', 'https://ikea.is/is/search/?q=80366284'); // $body= $res->getBody()->getContents(); $dochtml = new \DOMDocument(); - @$dochtml->loadHTML('' . $body); + @$dochtml->loadHTML( $body); - $xpath = new \DOMXpath($dochtml); + @$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; + @$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; + @$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; + @$url_product = "https://www.ikea.is" . $xpath->query('/html/head/meta[(@property="og:url")]/@content')[0]->nodeValue; //echo "url_product: " . $url_product . "
";