Fix search, remove, add countries

This commit is contained in:
2023-12-25 21:45:08 +01:00
parent 4375ac1fc8
commit 82c9971289
4 changed files with 43 additions and 14 deletions

View File

@@ -10,4 +10,5 @@ class CurrencyRatesController extends Controller
{
return CurrencyRates::all();
}
}

View File

@@ -8,6 +8,7 @@ use Illuminate\Http\Client\Pool;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use App\Models\CountryCode;
use App\Models\CurrencyRates;
use Inertia\Inertia;
class ProductsCompareController extends Controller
@@ -20,21 +21,34 @@ class ProductsCompareController extends Controller
Log::info("{codes} {countries}", ["codes" => $codes, "countries" => $countries]);
$codes = collect($codes);
// $countries = collect(json_decode($countries, true));
$countries = collect($countries);
if ($countries != null && count($countries)) {
$hCountry = CountryCode::countryHash();
$countries = $countries->map(function ($country) {
return $hCountry[$country];
if ($countries != null && count($countries)) {
$hCountry = CountryCode::countryHash();
$countries = $countries->map(function ($country) use ($hCountry) {
return $hCountry[$country];
});
} else {
$countries = [];
}
if (is_array($codes) == false)
$aCodes = [$codes['code']];
else
$aCodes = $codes->map(function ($code) {
return $code['code'];
});
$products = IkeaProducts::whereIn("code", $aCodes);
if (count($countries)) $products->whereIn("country",$countries);
$products = $products->get();
$currencyRates = CurrencyRates::rates2EUR("Y");
$products = $products->map(function ($product) use ($currencyRates) {
$product["salesPrice"] = round(floatval($product["salesPrice"]) / $currencyRates[$product["country"]], 2);
return $product;
});
}
// $aCodes = $codes->map(function ($code) {
// return $code['code'];
// });
$aCodes = $codes['code'];
$products = IkeaProducts::where("code", $aCodes)->get();
Log::info("{products}", ["products" => $products]);
return Inertia::render('IkeaRoot', [
'products' => $products