This commit is contained in:
@@ -10,8 +10,8 @@ use Illuminate\Support\Facades\Log;
|
|||||||
|
|
||||||
class IkeaProductsController extends Controller
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,14 +24,18 @@ class IkeaProducts extends Model
|
|||||||
*/
|
*/
|
||||||
public $incrementing = false;
|
public $incrementing = false;
|
||||||
|
|
||||||
protected function search($item)
|
protected function search($item,$country = '')
|
||||||
{
|
{
|
||||||
if (strlen($item) >= 2 && strlen($item) <= 5) {
|
if (strlen($item) >= 2 && strlen($item) < 5) {
|
||||||
return $this->where('name', 'LIKE', $item . '%')->get();
|
$result = $this->where('name', 'LIKE', $item . '%');
|
||||||
|
if ($country != '') $result = $result->where('country',$country);
|
||||||
|
return $result->get();
|
||||||
} else if (strlen($item >= 5)) {
|
} else if (strlen($item >= 5)) {
|
||||||
return $this->where('typeName', 'LIKE', '%' . $item . '%')->orWhere('name', 'LIKE', '%' . $item . '%')->get();
|
if ($country != '') $result = $this->where('country',$country);
|
||||||
} else {
|
$result = $result->where(function ($query) use ($item) { $query->where('typeName', 'LIKE', '%' . $item . '%')->orWhere('name', 'LIKE', '%' . $item . '%'); } );
|
||||||
return [];
|
|
||||||
|
return $result->get();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,5 +108,6 @@
|
|||||||
"referenceerror: rates is not defined": "ReferenceError: rates is not defined",
|
"referenceerror: rates is not defined": "ReferenceError: rates is not defined",
|
||||||
"referenceerror: currency is not defined": "ReferenceError: currency 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",
|
"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"
|
||||||
}
|
}
|
||||||
@@ -39,9 +39,12 @@ let tproducts = computed(() => {
|
|||||||
const type = 'GeoChart';
|
const type = 'GeoChart';
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
countries: '',
|
countries: '',
|
||||||
|
country: '',
|
||||||
codes: '',
|
codes: '',
|
||||||
currency: 'EUR',
|
currency: 'EUR',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const ccodes = ref([]);
|
||||||
const ccountry = ref([]);
|
const ccountry = ref([]);
|
||||||
const ccountry_filter = ref([['Country'],]);
|
const ccountry_filter = ref([['Country'],]);
|
||||||
const ccountry_list = ref(['TEST']);
|
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) => {
|
const async_search = async (item) => {
|
||||||
try {
|
try {
|
||||||
if (item.length >= 2) {
|
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 } });
|
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);
|
console.log("VALUES=", options_items.value);
|
||||||
}
|
}
|
||||||
@@ -150,6 +173,7 @@ const async_search = async (item) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function customLabel({ item, desc }) {
|
function customLabel({ item, desc }) {
|
||||||
//console.log(item);
|
//console.log(item);
|
||||||
return `${item} - ${desc}`;
|
return `${item} - ${desc}`;
|
||||||
@@ -172,6 +196,7 @@ function selectCountry(item, id) {
|
|||||||
|
|
||||||
onMounted(fetch);
|
onMounted(fetch);
|
||||||
onMounted(fetch_rates);
|
onMounted(fetch_rates);
|
||||||
|
onMounted(fetch_ccodes);
|
||||||
|
|
||||||
const submit = () => {
|
const submit = () => {
|
||||||
console.log('ITEM=', form);
|
console.log('ITEM=', form);
|
||||||
@@ -204,6 +229,13 @@ const submit = () => {
|
|||||||
@select="selectCountry" @remove="selectCountry">
|
@select="selectCountry" @remove="selectCountry">
|
||||||
</multiselect>
|
</multiselect>
|
||||||
</div>
|
</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>
|
<div>
|
||||||
<span class="font-extrabold font-mono">Zadaj polozku</span>
|
<span class="font-extrabold font-mono">Zadaj polozku</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -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('/ccountry/active/', [CountryCodeController::class, 'active'])->name('ccountry.active');
|
||||||
Route::get('/search/{id}',[CountryCompareController::class,'search'])->name('ccompare.search');
|
Route::get('/search/{id}',[CountryCompareController::class,'search'])->name('ccompare.search');
|
||||||
Route::get('/rates/', [CurrencyRatesController::class, 'index'])->name('rates.index');
|
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::post('/products/compare/', [ProductsCompareController::class, 'compare'])->name('products.compare');
|
||||||
|
|
||||||
Route::middleware(['auth:sanctum', config('jetstream.auth_session'), 'verified'])->group(function () {
|
Route::middleware(['auth:sanctum', config('jetstream.auth_session'), 'verified'])->group(function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user