Fix search, remove, add countries
This commit is contained in:
@@ -10,4 +10,5 @@ class CurrencyRatesController extends Controller
|
|||||||
{
|
{
|
||||||
return CurrencyRates::all();
|
return CurrencyRates::all();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use Illuminate\Http\Client\Pool;
|
|||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use App\Models\CountryCode;
|
use App\Models\CountryCode;
|
||||||
|
use App\Models\CurrencyRates;
|
||||||
use Inertia\Inertia;
|
use Inertia\Inertia;
|
||||||
|
|
||||||
class ProductsCompareController extends Controller
|
class ProductsCompareController extends Controller
|
||||||
@@ -20,21 +21,34 @@ class ProductsCompareController extends Controller
|
|||||||
Log::info("{codes} {countries}", ["codes" => $codes, "countries" => $countries]);
|
Log::info("{codes} {countries}", ["codes" => $codes, "countries" => $countries]);
|
||||||
|
|
||||||
$codes = collect($codes);
|
$codes = collect($codes);
|
||||||
// $countries = collect(json_decode($countries, true));
|
$countries = collect($countries);
|
||||||
|
|
||||||
if ($countries != null && count($countries)) {
|
if ($countries != null && count($countries)) {
|
||||||
$hCountry = CountryCode::countryHash();
|
$hCountry = CountryCode::countryHash();
|
||||||
$countries = $countries->map(function ($country) {
|
$countries = $countries->map(function ($country) use ($hCountry) {
|
||||||
return $hCountry[$country];
|
return $hCountry[$country];
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
$countries = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// $aCodes = $codes->map(function ($code) {
|
if (is_array($codes) == false)
|
||||||
// return $code['code'];
|
$aCodes = [$codes['code']];
|
||||||
// });
|
else
|
||||||
|
$aCodes = $codes->map(function ($code) {
|
||||||
|
return $code['code'];
|
||||||
|
});
|
||||||
|
|
||||||
$aCodes = $codes['code'];
|
$products = IkeaProducts::whereIn("code", $aCodes);
|
||||||
$products = IkeaProducts::where("code", $aCodes)->get();
|
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;
|
||||||
|
});
|
||||||
Log::info("{products}", ["products" => $products]);
|
Log::info("{products}", ["products" => $products]);
|
||||||
return Inertia::render('IkeaRoot', [
|
return Inertia::render('IkeaRoot', [
|
||||||
'products' => $products
|
'products' => $products
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Models;
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use App\Models\CountryCode;
|
||||||
|
|
||||||
class CurrencyRates extends Model
|
class CurrencyRates extends Model
|
||||||
{
|
{
|
||||||
@@ -34,4 +35,16 @@ class CurrencyRates extends Model
|
|||||||
{
|
{
|
||||||
return $this->get();
|
return $this->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function rates2EUR(String $status)
|
||||||
|
{
|
||||||
|
$rates = $this->actual("Y")->mapWithKeys(function ($item) {
|
||||||
|
return [$item['currency'] => $item['rate']];
|
||||||
|
});
|
||||||
|
|
||||||
|
return CountryCode::active("Y")->mapWithKeys(function ($item) use ($rates) {
|
||||||
|
if ($item['currency_code'] == "EUR") return [$item["country_code"] => 1.0];
|
||||||
|
return [$item["country_code"] => $rates[$item["currency_code"]]];
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,7 +156,8 @@ const items = ref([]);
|
|||||||
|
|
||||||
function selectCountry(item, id) {
|
function selectCountry(item, id) {
|
||||||
let cCntry = [['Country'],];
|
let cCntry = [['Country'],];
|
||||||
let aCntry = selected.value.map((country) => [country]);
|
console.log(form.countries);
|
||||||
|
let aCntry = form.countries.map((country) => [country]);
|
||||||
|
|
||||||
ccountry_filter.value = cCntry;
|
ccountry_filter.value = cCntry;
|
||||||
ccountry_filter.value.push(...aCntry);
|
ccountry_filter.value.push(...aCntry);
|
||||||
|
|||||||
Reference in New Issue
Block a user