Fix search, remove, add countries
This commit is contained in:
@@ -10,4 +10,5 @@ class CurrencyRatesController extends Controller
|
||||
{
|
||||
return CurrencyRates::all();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\CountryCode;
|
||||
|
||||
class CurrencyRates extends Model
|
||||
{
|
||||
@@ -34,4 +35,16 @@ class CurrencyRates extends Model
|
||||
{
|
||||
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) {
|
||||
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.push(...aCntry);
|
||||
|
||||
Reference in New Issue
Block a user