search with country
Some checks are pending
deploy / deploy (push) Waiting to run

This commit is contained in:
2024-01-03 20:44:19 +01:00
parent 597f9c111f
commit fbcc3226fe
5 changed files with 48 additions and 11 deletions

View File

@@ -10,8 +10,8 @@ use Illuminate\Support\Facades\Log;
class IkeaProductsController extends Controller
{
public function search(Request $request, string $item)
public function search(Request $request, string $item, string $country = '')
{
return IkeaProducts::search($item);
return IkeaProducts::search($item, $country);
}
}

View File

@@ -24,14 +24,18 @@ class IkeaProducts extends Model
*/
public $incrementing = false;
protected function search($item)
protected function search($item,$country = '')
{
if (strlen($item) >= 2 && strlen($item) <= 5) {
return $this->where('name', 'LIKE', $item . '%')->get();
if (strlen($item) >= 2 && strlen($item) < 5) {
$result = $this->where('name', 'LIKE', $item . '%');
if ($country != '') $result = $result->where('country',$country);
return $result->get();
} else if (strlen($item >= 5)) {
return $this->where('typeName', 'LIKE', '%' . $item . '%')->orWhere('name', 'LIKE', '%' . $item . '%')->get();
} else {
return [];
if ($country != '') $result = $this->where('country',$country);
$result = $result->where(function ($query) use ($item) { $query->where('typeName', 'LIKE', '%' . $item . '%')->orWhere('name', 'LIKE', '%' . $item . '%'); } );
return $result->get();
}
}

View File

@@ -108,5 +108,6 @@
"referenceerror: rates is not defined": "ReferenceError: rates is not defined",
"referenceerror: currency is not defined": "ReferenceError: currency is not defined",
"typeerror: can't access property \"unshift\", currency.velue is undefined": "TypeError: can't access property \"unshift\", currency.velue is undefined",
"item must be selected": "Item must be selected"
"item must be selected": "Item must be selected",
"typeerror: can't access property \"code\", form.country.value is undefined": "TypeError: can't access property \"code\", form.country.value is undefined"
}

View File

@@ -39,9 +39,12 @@ let tproducts = computed(() => {
const type = 'GeoChart';
const form = useForm({
countries: '',
country: '',
codes: '',
currency: 'EUR',
});
const ccodes = ref([]);
const ccountry = ref([]);
const ccountry_filter = ref([['Country'],]);
const ccountry_list = ref(['TEST']);
@@ -130,10 +133,30 @@ const fetch_rates = async () => {
}
}
const fetch_ccodes = async () => {
try {
const response = await axios.get(route('ccountry.codes'))
ccodes.value = response.data;
ccodes.value = Object.entries(ccodes.value).map(([k,v]) => { if (v !== null) return { "country": k, "code": v } } ).filter( n => n);
console.log("ccodes=", ccodes.value);
} catch (e) {
const response = await Swal.fire({
title: __('are you want to try again') + '?',
text: __(`${e}`),
icon: 'question',
showCancelButton: true,
showCloseButton: true,
})
response.isConfirmed && fetch()
}
}
const async_search = async (item) => {
try {
if (item.length >= 2) {
const response = await axios.get(route('products.search', item));
console.log('SEARCH',item,form.country.code,route('products.search', [item, form.country.code]));
const response = await axios.get(route('products.search', [item, form.country.code]));
options_items.value = response.data.map((i) => { return { "item": i.name, "desc": i.typeName, "img": i.mainImageUrl, "code": i.code } });
console.log("VALUES=", options_items.value);
}
@@ -150,6 +173,7 @@ const async_search = async (item) => {
}
}
function customLabel({ item, desc }) {
//console.log(item);
return `${item} - ${desc}`;
@@ -172,6 +196,7 @@ function selectCountry(item, id) {
onMounted(fetch);
onMounted(fetch_rates);
onMounted(fetch_ccodes);
const submit = () => {
console.log('ITEM=', form);
@@ -204,6 +229,13 @@ const submit = () => {
@select="selectCountry" @remove="selectCountry">
</multiselect>
</div>
<div class="flex flex-col start-0">
<span class="font-extrabold font-mono">Krajina produktu na vyhladanie</span>
</div>
<div>
<multiselect :close-on-select="false" :multiple="false" v-model="form.country" :options="ccodes" label="country" track-by="code">
</multiselect>
</div>
<div>
<span class="font-extrabold font-mono">Zadaj polozku</span>
</div>

View File

@@ -37,7 +37,7 @@ Route::get('/ccountry/codes/', [CountryCodeController::class, 'codes'])->name('c
Route::get('/ccountry/active/', [CountryCodeController::class, 'active'])->name('ccountry.active');
Route::get('/search/{id}',[CountryCompareController::class,'search'])->name('ccompare.search');
Route::get('/rates/', [CurrencyRatesController::class, 'index'])->name('rates.index');
Route::get('/products/{item}', [IkeaProductsController::class, 'search'])->name('products.search');
Route::get('/products/{item}/{country?}', [IkeaProductsController::class, 'search'])->name('products.search');
Route::post('/products/compare/', [ProductsCompareController::class, 'compare'])->name('products.compare');
Route::middleware(['auth:sanctum', config('jetstream.auth_session'), 'verified'])->group(function () {