Basic online search with bugs...
This commit is contained in:
@@ -16,6 +16,10 @@ tasks:
|
|||||||
build:
|
build:
|
||||||
cmds:
|
cmds:
|
||||||
- vendor/bin/dep build
|
- vendor/bin/dep build
|
||||||
|
ikeaweb01:
|
||||||
|
cmds:
|
||||||
|
- vendor/bin/dep deploy web01.ttx.sk
|
||||||
|
- vendor/bin/dep build web01.ttx.sk
|
||||||
ssh:
|
ssh:
|
||||||
cmds:
|
cmds:
|
||||||
- vendor/bin/dep ssh
|
- vendor/bin/dep ssh
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ class IkeaPrices extends Command
|
|||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'ikea:prices {article}';
|
protected $signature = 'ikea:prices {article}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = 'Get Ikea Prices';
|
protected $description = 'Get Ikea Prices';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*
|
*
|
||||||
@@ -30,9 +30,9 @@ class IkeaPrices extends Command
|
|||||||
{
|
{
|
||||||
$article = $this->argument('article');
|
$article = $this->argument('article');
|
||||||
$responses = $countryCompareController->makeRequests($article);
|
$responses = $countryCompareController->makeRequests($article);
|
||||||
$prices = $countryCompareController->processResponse($responses,$article);
|
$products = $countryCompareController->processResponse($responses,$article);
|
||||||
//dd($prices);
|
|
||||||
return 0;
|
dd($products);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
36
app/Console/Commands/OnlineTestCommand.php
Normal file
36
app/Console/Commands/OnlineTestCommand.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use App\Http\Controllers\OnlineCompareController;
|
||||||
|
|
||||||
|
class OnlineTestCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'ikea:online';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Command description';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function handle(OnlineCompareController $onlineCompareController)
|
||||||
|
{
|
||||||
|
//$article = $this->argument('article');
|
||||||
|
$prices = $onlineCompareController->compare();
|
||||||
|
dd($prices);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
app/Console/Commands/TestOnline.php
Normal file
37
app/Console/Commands/TestOnline.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use App\Http\Controllers\OnlineCompareController;
|
||||||
|
|
||||||
|
class OnlinePrices extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'ikea:online';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Online Ikea Prices';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function handle(OnlineCompareController $onlineCompareController)
|
||||||
|
{
|
||||||
|
//$article = $this->argument('article');
|
||||||
|
$prices = $onlineCompareController->compare();
|
||||||
|
dd($prices);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -12,15 +12,19 @@ use PHPHtmlParser\Dom;
|
|||||||
class CountryCompareController extends Controller
|
class CountryCompareController extends Controller
|
||||||
{
|
{
|
||||||
private $countries = [];
|
private $countries = [];
|
||||||
|
private $cHash = [];
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$countries = [];
|
$countries = [];
|
||||||
CountryCode::all()->each(function ($country) use (&$countries) {
|
$cHash = [];
|
||||||
$countries[] = $country->country_name;
|
CountryCode::active('Y')->each(function ($country) use (&$countries, &$cHash) {
|
||||||
|
$countries[] = $country;
|
||||||
|
$cHash[$country->country_name] = $country->country_code;
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->countries = collect($countries);
|
$this->countries = collect($countries);
|
||||||
|
$this->cHash = collect($cHash);
|
||||||
}
|
}
|
||||||
public function search(Request $request)
|
public function search(Request $request)
|
||||||
{
|
{
|
||||||
@@ -31,13 +35,16 @@ class CountryCompareController extends Controller
|
|||||||
return $this->processResponse($requests,$ta_codes[0]);
|
return $this->processResponse($requests,$ta_codes[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function compare($countries, $cHash, $aCodes){
|
||||||
|
$requests = $this->makeRequests($aCodes);
|
||||||
|
return $this->processResponse($requests, $aCodes);
|
||||||
|
}
|
||||||
public function makeRequests($ta_code)
|
public function makeRequests($ta_code)
|
||||||
{
|
{
|
||||||
$requests = Http::pool(fn (Pool $pool) => [
|
$requests = Http::pool(fn (Pool $pool) => [
|
||||||
CountryCode::all()->each(function ($countryCode) use ($pool, $ta_code) {
|
$this->countries->each(function ($country) use ($pool, $ta_code) {
|
||||||
$this->countries[] = $countryCode->country_name;
|
Log::info('Getting page {url}', [ 'url' => $country->search_url . $ta_code ] );
|
||||||
Log::info('Getting page {url}', [ 'url' => $countryCode->search_url . $ta_code ] );
|
return $pool->as($country->country_code)->get($country->search_url . $ta_code);
|
||||||
return $pool->as($countryCode->country_name)->get($countryCode->search_url . $ta_code);
|
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
return $requests;
|
return $requests;
|
||||||
@@ -45,9 +52,9 @@ class CountryCompareController extends Controller
|
|||||||
|
|
||||||
public function makeRequest($ta_code, $country)
|
public function makeRequest($ta_code, $country)
|
||||||
{
|
{
|
||||||
$countryCode = CountryCode::where('country_name', $country)->first();
|
$country = CountryCode::where('country_name', $country)->first();
|
||||||
return Http::pool(fn (Pool $pool) => [
|
return Http::pool(fn (Pool $pool) => [
|
||||||
$pool->as($countryCode->country_name)->get($countryCode->search_url . $ta_code)
|
$pool->as($country->country_name)->get($country->search_url . $ta_code)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,38 +62,49 @@ class CountryCompareController extends Controller
|
|||||||
{
|
{
|
||||||
$prices = [];
|
$prices = [];
|
||||||
|
|
||||||
foreach ($this->countries as $country) {
|
foreach ($this->countries as $c) {
|
||||||
|
|
||||||
if (isset($responses[$country]) && $responses[$country]->ok()) {
|
$country = $c->country_code;
|
||||||
|
|
||||||
|
if ($responses[$country] instanceof \Illuminate\Http\Client\Response && $responses[$country]->ok()) {
|
||||||
|
|
||||||
$response = $responses[$country]->body();
|
$response = $responses[$country]->body();
|
||||||
switch ($country) {
|
switch ($country) {
|
||||||
case "Bulgaria":
|
case "BG":
|
||||||
case "Cyprus":
|
case "BY":
|
||||||
case "Greece":
|
case "GR":
|
||||||
$prices[$country] = $this->parseJson_CY_GR_BG($code, (string) $response);
|
$prices[$country] = $this->parseJson_CY_GR_BG($code, (string) $response, $country);
|
||||||
break;
|
break;
|
||||||
case "Iceland":
|
case "IS":
|
||||||
$prices[$country] = $this->parseJson_IS($country, $code, (string) $response);
|
$prices[$country] = $this->parseJson_IS($code, (string) $response, $country);
|
||||||
break;
|
break;
|
||||||
case "Türkiye":
|
case "TR":
|
||||||
$prices[$country] = $this->parseJson_TR((string) $response);
|
$prices[$country] = $this->parseJson_TR((string) $response, $country);
|
||||||
break;
|
break;
|
||||||
case "Lithuania":
|
case "EE":
|
||||||
case "Estonia":
|
case "LT":
|
||||||
case "Latvia":
|
case "LV":
|
||||||
$prices[$country] = $this->parseJson_EE_LT_LV($country, $code, (string) $response);
|
$prices[$country] = $this->parseJson_EE_LT_LV($code, (string) $response, $country);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$prices[$country] = $this->parseJson((string) $response);
|
$prices[$country] = $this->parseJson((string) $response, $country);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $prices;
|
$products = [];
|
||||||
|
collect($prices)->each(function ($price) use (&$products) {
|
||||||
|
if (count($price))
|
||||||
|
$products[] = $price;
|
||||||
|
});
|
||||||
|
return collect($products);
|
||||||
}
|
}
|
||||||
public function parseJson($json_raw)
|
|
||||||
|
// { "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)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$json_values = array();
|
$json_values = array();
|
||||||
|
|
||||||
$json_decoded = json_decode($json_raw, true);
|
$json_decoded = json_decode($json_raw, true);
|
||||||
@@ -103,18 +121,21 @@ class CountryCompareController extends Controller
|
|||||||
$numeral = $salesPrice["numeral"];
|
$numeral = $salesPrice["numeral"];
|
||||||
|
|
||||||
$json_values = array(
|
$json_values = array(
|
||||||
'url_product' => $product['pipUrl'],
|
'url' => $product['pipUrl'],
|
||||||
'tag' => $product['tag'],
|
'tag' => $product['tag'],
|
||||||
'price' => $numeral,
|
'country' => $country,
|
||||||
'price_eur' => 0
|
'salesPrice' => $numeral,
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
return $json_values;
|
return $json_values;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseJson_TR($body)
|
public function parseJson_TR($body,$country)
|
||||||
{
|
{
|
||||||
//echo "country: " . $country . ", code: " . $code . "<br>";
|
//echo "country: " . $country . ", code: " . $code . "<br>";
|
||||||
|
|
||||||
@@ -132,16 +153,16 @@ class CountryCompareController extends Controller
|
|||||||
$price = floatval(trim(str_replace('.', '', $price)));
|
$price = floatval(trim(str_replace('.', '', $price)));
|
||||||
|
|
||||||
$json_values = array(
|
$json_values = array(
|
||||||
'url_product' => $url_product,
|
'url' => $url_product,
|
||||||
'tag' => null,
|
'tag' => null,
|
||||||
'price' => floatval($price),
|
'price' => floatval($price),
|
||||||
'price_eur' => 0
|
'country' => $country,
|
||||||
);
|
);
|
||||||
|
|
||||||
return $json_values;
|
return $json_values;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseJson_CY_GR_BG($code, $body)
|
public function parseJson_CY_GR_BG($code, $body , $country)
|
||||||
{
|
{
|
||||||
//echo "country: " . $country . ", code: " . $code . "<br>";
|
//echo "country: " . $country . ", code: " . $code . "<br>";
|
||||||
|
|
||||||
@@ -163,16 +184,16 @@ class CountryCompareController extends Controller
|
|||||||
|
|
||||||
|
|
||||||
$json_values = array(
|
$json_values = array(
|
||||||
'url_product' => $url_product,
|
'url' => $url_product,
|
||||||
'tag' => null,
|
'tag' => null,
|
||||||
'price' => floatval($price),
|
'price' => floatval($price),
|
||||||
'price_eur' => 0
|
'country' => $country,
|
||||||
);
|
);
|
||||||
|
|
||||||
return $json_values;
|
return $json_values;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseJson_EE_LT_LV($country, $code, $body)
|
public function parseJson_EE_LT_LV($code, $body, $country)
|
||||||
{
|
{
|
||||||
//echo "country: " . $country . ", code: " . $code . "<br>";
|
//echo "country: " . $country . ", code: " . $code . "<br>";
|
||||||
|
|
||||||
@@ -192,13 +213,13 @@ class CountryCompareController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch ($country) {
|
switch ($country) {
|
||||||
case "Estonia":
|
case "EE":
|
||||||
$url_product = "https://www.ikea.ee" . $xpath->query('//*/div[(@class="card-header")]/a/@href')[0]->nodeValue;
|
$url_product = "https://www.ikea.ee" . $xpath->query('//*/div[(@class="card-header")]/a/@href')[0]->nodeValue;
|
||||||
break;
|
break;
|
||||||
case "Lithuania":
|
case "LT":
|
||||||
$url_product = "https://www.ikea.lt" . $xpath->query('//*/div[(@class="card-header")]/a/@href')[0]->nodeValue;
|
$url_product = "https://www.ikea.lt" . $xpath->query('//*/div[(@class="card-header")]/a/@href')[0]->nodeValue;
|
||||||
break;
|
break;
|
||||||
case "Latvia":
|
case "LV":
|
||||||
$url_product = "https://www.ikea.lv" . $xpath->query('//*/div[(@class="card-header")]/a/@href')[0]->nodeValue;
|
$url_product = "https://www.ikea.lv" . $xpath->query('//*/div[(@class="card-header")]/a/@href')[0]->nodeValue;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -215,17 +236,16 @@ class CountryCompareController extends Controller
|
|||||||
$price = floatval(trim(str_replace(' ', '', str_replace(',', '.', str_replace(array('€'), '', $price)))));
|
$price = floatval(trim(str_replace(' ', '', str_replace(',', '.', str_replace(array('€'), '', $price)))));
|
||||||
|
|
||||||
$json_values = array(
|
$json_values = array(
|
||||||
'url_product' => $url_product,
|
'url' => $url_product,
|
||||||
//$url_product,
|
|
||||||
'tag' => null,
|
'tag' => null,
|
||||||
'price' => $price,
|
'price' => $price,
|
||||||
'price_eur' => 0
|
'country' => $country,
|
||||||
);
|
);
|
||||||
|
|
||||||
return $json_values;
|
return $json_values;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseJson_IS($country, $code, $body)
|
public function parseJson_IS($code, $body, $country)
|
||||||
{
|
{
|
||||||
//echo "country: " . $country . ", code: " . $code . "<br>";
|
//echo "country: " . $country . ", code: " . $code . "<br>";
|
||||||
|
|
||||||
@@ -258,11 +278,10 @@ class CountryCompareController extends Controller
|
|||||||
$price = floatval(trim(str_replace(' ', '', str_replace(',', '.', str_replace('.', '', str_replace(array('€'), '', $price))))));
|
$price = floatval(trim(str_replace(' ', '', str_replace(',', '.', str_replace('.', '', str_replace(array('€'), '', $price))))));
|
||||||
|
|
||||||
$json_values = array(
|
$json_values = array(
|
||||||
'url_product' => $url_product,
|
'url' => $url_product,
|
||||||
//$url_product,
|
|
||||||
'tag' => null,
|
'tag' => null,
|
||||||
'price' => $price,
|
'price' => $price,
|
||||||
'price_eur' => 0
|
'country' => $country,
|
||||||
);
|
);
|
||||||
|
|
||||||
return $json_values;
|
return $json_values;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use Illuminate\Support\Facades\Log;
|
|||||||
|
|
||||||
class IkeaProductsController extends Controller
|
class IkeaProductsController extends Controller
|
||||||
{
|
{
|
||||||
public function search(Request $request, string $field, string $text, ?string $country = '')
|
public function search(Request $request, string $field, string $text, ?string $country = '', $online = false)
|
||||||
{
|
{
|
||||||
return IkeaProducts::search($field, $text, $country);
|
return IkeaProducts::search($field, $text, $country);
|
||||||
}
|
}
|
||||||
|
|||||||
326
app/Http/Controllers/OnlineCompareController.php
Normal file
326
app/Http/Controllers/OnlineCompareController.php
Normal file
@@ -0,0 +1,326 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use GuzzleHttp\Client as GuzzleClient;
|
||||||
|
use GuzzleHttp\Promise as GuzzlePromise;
|
||||||
|
|
||||||
|
use App\Models\CountryCode;
|
||||||
|
|
||||||
|
function parseJson($json_raw)
|
||||||
|
{
|
||||||
|
$json_values = array();
|
||||||
|
|
||||||
|
$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' => $product['pipUrl'],
|
||||||
|
'tag' => $product['tag'],
|
||||||
|
'price' => $numeral,
|
||||||
|
'price_eur' => 0
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $json_values;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseJson_TR($body)
|
||||||
|
{
|
||||||
|
//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_product' => $url_product,
|
||||||
|
'tag' => null,
|
||||||
|
'price' => floatval($price),
|
||||||
|
'price_eur' => 0
|
||||||
|
);
|
||||||
|
|
||||||
|
return $json_values;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseJson_CY_GR_BG($code, $body)
|
||||||
|
{
|
||||||
|
//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="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,
|
||||||
|
'price' => floatval($price),
|
||||||
|
'price_eur' => 0
|
||||||
|
);
|
||||||
|
|
||||||
|
return $json_values;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseJson_EE_LT_LV($country, $code, $body)
|
||||||
|
{
|
||||||
|
//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 "Estonia":
|
||||||
|
$url_product = "https://www.ikea.ee" . $xpath->query('//*/div[(@class="card-header")]/a/@href')[0]->nodeValue;
|
||||||
|
break;
|
||||||
|
case "Lithuania":
|
||||||
|
$url_product = "https://www.ikea.lt" . $xpath->query('//*/div[(@class="card-header")]/a/@href')[0]->nodeValue;
|
||||||
|
break;
|
||||||
|
case "Latvia":
|
||||||
|
$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_product' => $url_product,
|
||||||
|
//$url_product,
|
||||||
|
'tag' => null,
|
||||||
|
'price' => $price,
|
||||||
|
'price_eur' => 0
|
||||||
|
);
|
||||||
|
|
||||||
|
return $json_values;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseJson_IS($country, $code, $body)
|
||||||
|
{
|
||||||
|
//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")]//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;
|
||||||
|
}
|
||||||
|
|
||||||
|
$price = floatval(trim(str_replace(' ', '', str_replace(',', '.', str_replace('.', '', str_replace(array('€'), '', $price))))));
|
||||||
|
|
||||||
|
$json_values = array(
|
||||||
|
'url_product' => $url_product,
|
||||||
|
//$url_product,
|
||||||
|
'tag' => null,
|
||||||
|
'price' => $price,
|
||||||
|
'price_eur' => 0
|
||||||
|
);
|
||||||
|
|
||||||
|
return $json_values;
|
||||||
|
}
|
||||||
|
|
||||||
|
class OnlineCompareController extends Controller
|
||||||
|
{
|
||||||
|
private $countries = [];
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$countries = [];
|
||||||
|
CountryCode::all()->each(function ($country) use (&$countries) {
|
||||||
|
$countries[] = $country->country_name;
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->countries = collect($countries);
|
||||||
|
}
|
||||||
|
public function compare()
|
||||||
|
{
|
||||||
|
// $codes = $request->input("codes");
|
||||||
|
// $countries = $request->input("countries");
|
||||||
|
// $currency = $request->input("currency");
|
||||||
|
$codes = ['00102452',];
|
||||||
|
$countries = ['Austria', 'Belgium'];
|
||||||
|
$ta_codes = $codes;
|
||||||
|
$exch_rates = "EUR";
|
||||||
|
|
||||||
|
$item = array();
|
||||||
|
$codes = array();
|
||||||
|
|
||||||
|
// krajiny ktore som pridal do zoznamu z DB
|
||||||
|
$added_countries[] = null;
|
||||||
|
|
||||||
|
// loop cez jednotlive code z textarea a pridanie url
|
||||||
|
/* ******************************************************************** */
|
||||||
|
foreach ($ta_codes as $code) {
|
||||||
|
unset($item);
|
||||||
|
|
||||||
|
if (!is_numeric($code) || strlen($code) < 6) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($countries as $country) {
|
||||||
|
|
||||||
|
if (!in_array($country['country_name'], $added_countries)) {
|
||||||
|
|
||||||
|
$item[] = array(
|
||||||
|
'country_name' => $country['country_name'],
|
||||||
|
'url_call' => $country['search_url'] . $code,
|
||||||
|
'price' => 0,
|
||||||
|
'url_product' => null,
|
||||||
|
'tag' => null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$codes[] = array(
|
||||||
|
'code' => $code,
|
||||||
|
'item' => $item
|
||||||
|
);
|
||||||
|
}
|
||||||
|
//echo var_dump($codes);
|
||||||
|
|
||||||
|
/* ******************************************************************** */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// paralelene prevolanie URL
|
||||||
|
/* ******************************************************************** */
|
||||||
|
$client = new GuzzleClient(['timeout' => 12.0]);
|
||||||
|
|
||||||
|
$promises[] = null;
|
||||||
|
$prices[] = null;
|
||||||
|
|
||||||
|
foreach ($codes as $x => $code) {
|
||||||
|
//echo "CODE: " . $code_value['code'] . "<BR>";
|
||||||
|
|
||||||
|
unset($promises);
|
||||||
|
unset($responses);
|
||||||
|
unset($prices);
|
||||||
|
|
||||||
|
// naplnenie pola promises URL
|
||||||
|
foreach ($code['item'] as $i => $i_value) {
|
||||||
|
if (!is_null($i_value['url_call'])) {
|
||||||
|
$promises[$i_value['country_name']] = $client->getAsync($i_value['url_call']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$responses = GuzzlePromise\settle($promises)->wait();
|
||||||
|
|
||||||
|
foreach ($responses as $country => $response) {
|
||||||
|
|
||||||
|
if ($response['state'] === 'fulfilled') {
|
||||||
|
$response_value = $response['value'];
|
||||||
|
|
||||||
|
if ($response_value->getStatusCode() == 200) {
|
||||||
|
|
||||||
|
switch ($country) {
|
||||||
|
case "Bulgaria":
|
||||||
|
case "Cyprus":
|
||||||
|
case "Greece":
|
||||||
|
$prices[$country] = parseJson_CY_GR_BG($code['code'], (string) $response_value->body());
|
||||||
|
break;
|
||||||
|
case "Iceland":
|
||||||
|
$prices[$country] = parseJson_IS($country, $code['code'], (string) $response_value->body());
|
||||||
|
break;
|
||||||
|
case "Turkey":
|
||||||
|
$prices[$country] = parseJson_TR((string) $response_value->body());
|
||||||
|
break;
|
||||||
|
case "Lithuania":
|
||||||
|
case "Estonia":
|
||||||
|
case "Latvia":
|
||||||
|
$prices[$country] = parseJson_EE_LT_LV($country, $code['code'], (string) $response_value->body());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$prices[$country] = parseJson((string) $response_value->body());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* {"products":{"Illuminate\\Database\\Eloquent\\Collection":[{"country":"AT","code":"00222671","url":"https://www.ikea.com/at
|
||||||
|
/de/p/vardoe-bettkasten-weiss-00222671/","name":"VARDÖ","typeName":"Bettkasten","mainImageUrl":"https://www.ikea.com/at/de/images/products/vardoe-bettkasten-weiss__0636
|
||||||
|
223_pe697736_s5.jpg","itemNoGlobal":"00222671","salesPrice":"34.99","tag":"NONE","last_mod":"2024-01-04 15:41:48","mainImageAlt":"VARDÖ Bettkasten, weiß, 65x70 cm","pri
|
||||||
|
ceUnit":null,"countryName":"Austria"} */
|
||||||
|
|
||||||
|
// zistenu cenu doplnim do kolekcie
|
||||||
|
foreach ($code['item'] as $i => $i_value) {
|
||||||
|
asort($codes[$x]['item']); // zotriedenie
|
||||||
|
$codes[$x]['item'][$i]['salesPrice'] = $prices[$i_value['country_name']]['price'] ?? 0;
|
||||||
|
|
||||||
|
|
||||||
|
if ($prices[$i_value['country_name']]['tag'] == 'NONE') {
|
||||||
|
$codes[$x]['item'][$i]['tag'] = "";
|
||||||
|
} else {
|
||||||
|
$codes[$x]['item'][$i]['tag'] = $prices[$i_value['country_name']]['tag'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$codes[$x]['item'][$i]['url'] = $prices[$i_value['country_name']]['url_product'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* ******************************************************************** */
|
||||||
|
|
||||||
|
|
||||||
|
// vypis do tabulky
|
||||||
|
/* ******************************************************************** */
|
||||||
|
return $codes;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,50 +10,60 @@ use Illuminate\Support\Facades\Log;
|
|||||||
use App\Models\CountryCode;
|
use App\Models\CountryCode;
|
||||||
use App\Models\CurrencyRates;
|
use App\Models\CurrencyRates;
|
||||||
use Inertia\Inertia;
|
use Inertia\Inertia;
|
||||||
|
use App\Http\Controllers\CountryCompareController;
|
||||||
|
|
||||||
class ProductsCompareController extends Controller
|
class ProductsCompareController extends Controller
|
||||||
{
|
{
|
||||||
public function compare(Request $request)
|
private $countryCompareController;
|
||||||
{
|
public function __construct(CountryCompareController $countryCompareController)
|
||||||
$codes = $request->input("codes");
|
{
|
||||||
$countries = $request->input("countries");
|
$this->countryCompareController = $countryCompareController;
|
||||||
$currency = $request->input("currency");
|
|
||||||
|
|
||||||
Log::info("{codes} {countries}", ["codes" => $codes, "countries" => $countries]);
|
|
||||||
|
|
||||||
$codes = collect($codes);
|
|
||||||
$countries = collect($countries);
|
|
||||||
|
|
||||||
if ($countries != null && count($countries)) {
|
|
||||||
$hCountry = CountryCode::countryHash();
|
|
||||||
$countries = $countries->map(function ($country) use ($hCountry) {
|
|
||||||
return $hCountry[$country];
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$countries = [];
|
|
||||||
}
|
}
|
||||||
|
public function compare(Request $request)
|
||||||
|
{
|
||||||
|
$codes = $request->input("codes");
|
||||||
|
$countries = $request->input("countries");
|
||||||
|
$online = $request->input("online");
|
||||||
|
|
||||||
$cHash = CountryCode::code_countryHash();
|
Log::info("{codes} {countries}", ["codes" => $codes, "countries" => $countries, "online" => $online]);
|
||||||
if (is_array($codes) == false)
|
|
||||||
$aCodes = $codes;
|
|
||||||
else
|
|
||||||
$aCodes = $codes->map(function ($code) {
|
|
||||||
return $code;
|
|
||||||
});
|
|
||||||
|
|
||||||
$products = IkeaProducts::whereIn("code", $aCodes);
|
$codes = collect($codes);
|
||||||
if (count($countries)) $products->whereIn("country",$countries);
|
$countries = collect($countries);
|
||||||
$products = $products->get();
|
|
||||||
|
|
||||||
|
if ($countries != null && count($countries)) {
|
||||||
|
$hCountry = CountryCode::countryHash();
|
||||||
|
$countries = $countries->map(function ($country) use ($hCountry) {
|
||||||
|
return $hCountry[$country];
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$countries = [];
|
||||||
|
}
|
||||||
|
|
||||||
$products = $products->map(function ($product) use ( $cHash) {
|
$cHash = CountryCode::code_countryHash();
|
||||||
$product["countryName"] = $cHash[$product["country"]];
|
if (is_array($codes) == false)
|
||||||
return $product;
|
$aCodes = $codes;
|
||||||
});
|
else
|
||||||
Log::info("{products}", ["products" => $products]);
|
$aCodes = $codes->map(function ($code) {
|
||||||
return [
|
return $code;
|
||||||
'products' => $products,
|
});
|
||||||
'countryHash' => $cHash,
|
|
||||||
];
|
if ($online == true) {
|
||||||
}
|
Log::info("ONLINE {codes} {countries}", ["codes" => $codes, "countries" => $countries, "online" => $online]);
|
||||||
|
$products = $this->countryCompareController->compare($countries, $cHash, $aCodes);
|
||||||
|
} else {
|
||||||
|
$products = IkeaProducts::whereIn("code", $aCodes);
|
||||||
|
if (count($countries)) $products->whereIn("country", $countries);
|
||||||
|
$products = $products->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
$products = $products->map(function ($product) use ($cHash) {
|
||||||
|
$product["countryName"] = $cHash[$product["country"]];
|
||||||
|
return $product;
|
||||||
|
});
|
||||||
|
Log::info("{products}", ["products" => $products]);
|
||||||
|
return [
|
||||||
|
'products' => $products,
|
||||||
|
'countryHash' => $cHash,
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,6 +168,7 @@ const form = useForm({
|
|||||||
field: sdropdown.value[0],
|
field: sdropdown.value[0],
|
||||||
text: "",
|
text: "",
|
||||||
currency: "EUR",
|
currency: "EUR",
|
||||||
|
online: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const ccodes = ref([]);
|
const ccodes = ref([]);
|
||||||
@@ -208,6 +209,11 @@ const sleep = (ms) => {
|
|||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onSelectCode = () => {
|
||||||
|
if (form.field.value == 'code') {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
const fetch = async () => {
|
const fetch = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(route("ccountry.active"));
|
const response = await axios.get(route("ccountry.active"));
|
||||||
@@ -302,12 +308,8 @@ const async_search = async () => {
|
|||||||
let country = null;
|
let country = null;
|
||||||
if (form.country.code !== undefined) country = form.country.code;
|
if (form.country.code !== undefined) country = form.country.code;
|
||||||
|
|
||||||
console.log(
|
|
||||||
"SEARCH",
|
|
||||||
route("products.search", [form.field.value, form.text, country])
|
|
||||||
);
|
|
||||||
const response = await axios.get(
|
const response = await axios.get(
|
||||||
route("products.search", [form.field.value, form.text, country])
|
route("products.search", [form.field.value, form.text, country, form.online])
|
||||||
);
|
);
|
||||||
|
|
||||||
options_items.value = response.data.map((i) => {
|
options_items.value = response.data.map((i) => {
|
||||||
@@ -323,6 +325,9 @@ const async_search = async () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
console.log("VALUES=", options_items.value);
|
console.log("VALUES=", options_items.value);
|
||||||
|
if (form.field.value == 'code') {
|
||||||
|
showRow({'code': form.text});
|
||||||
|
}
|
||||||
productsCriteria.value = null;
|
productsCriteria.value = null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const response = await Swal.fire({
|
const response = await Swal.fire({
|
||||||
@@ -367,6 +372,7 @@ const showRow = async (item) => {
|
|||||||
codes: item.code,
|
codes: item.code,
|
||||||
countries: form.countries,
|
countries: form.countries,
|
||||||
currency: form.currency,
|
currency: form.currency,
|
||||||
|
online: form.online,
|
||||||
});
|
});
|
||||||
|
|
||||||
products.value = response.data.products;
|
products.value = response.data.products;
|
||||||
@@ -473,7 +479,7 @@ watch(ccodes, (codes) => {
|
|||||||
<div class="mr-auto">
|
<div class="mr-auto">
|
||||||
<form @submit.prevent="submit">
|
<form @submit.prevent="submit">
|
||||||
<div>
|
<div>
|
||||||
<div class="grid grid-cols-2">
|
<div class="grid grid-cols-3">
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<span class="font-extrabold font-mono">Dynamic search:</span>
|
<span class="font-extrabold font-mono">Dynamic search:</span>
|
||||||
@@ -486,6 +492,19 @@ watch(ccodes, (codes) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="ml-2" >
|
||||||
|
<div v-if="form.field.value == 'code'">
|
||||||
|
<span class="font-extrabold font-mono">Online:</span>
|
||||||
|
</div>
|
||||||
|
<div v-if="form.field.value == 'code'">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600"
|
||||||
|
v-model="form.online"
|
||||||
|
@input="async_search"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="">
|
<div class="">
|
||||||
<div>
|
<div>
|
||||||
<span class="font-extrabold font-mono">Search in:</span>
|
<span class="font-extrabold font-mono">Search in:</span>
|
||||||
@@ -499,6 +518,7 @@ watch(ccodes, (codes) => {
|
|||||||
:options="sdropdown"
|
:options="sdropdown"
|
||||||
track-by="value"
|
track-by="value"
|
||||||
label="text"
|
label="text"
|
||||||
|
@select="onSelectCode"
|
||||||
></multiselect>
|
></multiselect>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use App\Http\Controllers\IkeaProductsController;
|
|||||||
use App\Http\Controllers\ProductsCompareController;
|
use App\Http\Controllers\ProductsCompareController;
|
||||||
use App\Http\Controllers\FeedbackController;
|
use App\Http\Controllers\FeedbackController;
|
||||||
use App\Http\Controllers\SettingsController;
|
use App\Http\Controllers\SettingsController;
|
||||||
|
use App\Http\Controllers\OnlineCompareController;
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Web Routes
|
| Web Routes
|
||||||
@@ -31,7 +32,7 @@ Route::get('/exchange/', function () {
|
|||||||
return Inertia::render('IkeaExchange');
|
return Inertia::render('IkeaExchange');
|
||||||
})->name('exchange');
|
})->name('exchange');
|
||||||
Route::post('users-send-email', [FeedbackController::class, 'sendEmail'])->name('ajax.send.email');
|
Route::post('users-send-email', [FeedbackController::class, 'sendEmail'])->name('ajax.send.email');
|
||||||
|
Route::get('/products/online', [OnlineCompareController::class,'compare'])->name('products.online.compare');
|
||||||
Route::get('/menu/get', [App\Http\Controllers\Superuser\UserMenuController::class, 'get'])->name('menu.user');
|
Route::get('/menu/get', [App\Http\Controllers\Superuser\UserMenuController::class, 'get'])->name('menu.user');
|
||||||
Route::get('/ip/get/{ip?}', [GeoIPController::class, 'index'])->name('geo.ip.get');
|
Route::get('/ip/get/{ip?}', [GeoIPController::class, 'index'])->name('geo.ip.get');
|
||||||
Route::get('/ccountry/', [CountryCodeController::class, 'index'])->name('ccountry.index');
|
Route::get('/ccountry/', [CountryCodeController::class, 'index'])->name('ccountry.index');
|
||||||
|
|||||||
Reference in New Issue
Block a user