diff --git a/app/Http/Controllers/ProductsCompareController.php b/app/Http/Controllers/ProductsCompareController.php index b84a862..1221c88 100644 --- a/app/Http/Controllers/ProductsCompareController.php +++ b/app/Http/Controllers/ProductsCompareController.php @@ -52,8 +52,9 @@ class ProductsCompareController extends Controller $coef = floatval(CurrencyRates::where('currency',$currency)->first()->rate); } - $products = $products->map(function ($product) use ($currencyRates, $coef) { + $products = $products->map(function ($product) use ($currencyRates, $coef, $cHash) { $product["salesPrice"] = round(floatval(($product["salesPrice"]) / $currencyRates[$product["country"]]) * $coef, 2); + $product["countryName"] = $cHash[$product["country"]]; return $product; }); Log::info("{products}", ["products" => $products]); diff --git a/resources/js/Pages/IkeaRoot.vue b/resources/js/Pages/IkeaRoot.vue index c89fba0..6f60f78 100644 --- a/resources/js/Pages/IkeaRoot.vue +++ b/resources/js/Pages/IkeaRoot.vue @@ -28,9 +28,9 @@ const props = defineProps({ }) const sdropdown = ref([ - { text: "Description", value: "typeName"}, - { text: "Item name", value: "name"}, - { text: "Code of product", value: "code"} + { text: "Description", value: "typeName" }, + { text: "Item name", value: "name" }, + { text: "Code of product", value: "code" } ]); @@ -40,7 +40,7 @@ const countryHash = ref([]); let tproducts = computed(() => { return products.value.map((prod) => { prod.salesPrice = parseFloat(prod.salesPrice); - prod.country = countryHash.value[prod.country]; + // prod.country = countryHash.value[prod.country]; return prod; }) }) @@ -58,9 +58,9 @@ const ccodes = ref([]); const ccountry = ref([]); const ccountry_filter = ref([['Country'],]); const ccountry_list = ref(['TEST']); -const selected = ref(null); -const article = ref(''); +const currencyHash = ref({}); const currency = ref([]); +const currencyCoef = ref(1.0); const hrates = ref([ { text: "Currency", value: "currency", sortable: true }, { text: "Country", value: "country_name", sortable: true }, @@ -68,15 +68,15 @@ const hrates = ref([ ]); // { "country": "AT", "code": "50161321", "url": "https://www.ikea.com/at/de/p/hol-aufbewahrungstisch-akazie-50161321/", "name": "HOL", "typeName": "Aufbewahrungstisch", "mainImageUrl": "https://www.ikea.com/at/de/images/products/hol-aufbewahrungstisch-akazie__0104310_pe251255_s5.jpg", "itemNoGlobal": "50161321", "salesPrice": "80.99", "tag": "FAMILY_PRICE", "last_mod": "2023-12-03 16:44:24" }, const hproducts = ref([ - { text: "Country", value: "country", sortable: true }, + { text: "Country", value: "countryName", sortable: true }, { text: "Name", value: "name", sortable: true }, { text: "Price", value: "salesPrice", sortable: true } ]); const hresults = ref([ - { text: "Code", value: "code", sortable: true}, - { text: "Name of product", value: "item", sortable: true}, - { text: "Description", value: "desc", sortable: true}, - { text: "Image", value: "img", sortable: false} + { text: "Code", value: "code", sortable: true }, + { text: "Name of product", value: "item", sortable: true }, + { text: "Description", value: "desc", sortable: true }, + { text: "Image", value: "img", sortable: false } ]) const rates = ref([]); const options_items = ref([]); @@ -135,8 +135,12 @@ const fetch_rates = async () => { const response = await axios.get(route('rates.index')) rates.value = response.data; currency.value = rates.value.map((currency) => currency.currency); + currencyHash.value = Object.fromEntries( + rates.value.map((currency) => [currency.currency, currency.rate]), + ); currency.value.unshift('EUR'); console.log("RATE=", rates.value); + console.log('HASH=', currencyHash.value); } catch (e) { const response = await Swal.fire({ title: __('are you want to try again') + '?', @@ -171,16 +175,16 @@ const fetch_ccodes = async () => { const async_search = async () => { if (form.text.length < 2) return; - + try { - let country = null; - if (form.country.code !== undefined) country = form.country.code; + let country = null; + if (form.country.code !== undefined) country = form.country.code; - console.log('SEARCH',route('products.search',[form.field.value, form.text, country])); - const response = await axios.get(route('products.search', [form.field.value, form.text, country])); + console.log('SEARCH', route('products.search', [form.field.value, form.text, country])); + const response = await axios.get(route('products.search', [form.field.value, form.text, country])); - options_items.value = response.data.map((i) => { return { "item": i.name, "desc": i.typeName, "img": i.mainImageUrl, "code": i.code, "url": i.url } }); - console.log("VALUES=", options_items.value); + options_items.value = response.data.map((i) => { return { "item": i.name, "desc": i.typeName, "img": i.mainImageUrl, "code": i.code, "url": i.url } }); + console.log("VALUES=", options_items.value); } catch (e) { const response = await Swal.fire({ title: __('are you want to try again') + '?', @@ -222,10 +226,10 @@ onMounted(fetch_ccodes); const showRow = async (item) => { console.log('ITEM=', item); console.log('FORM=', form); - + try { - const response = await axios.post(route('products.compare'),{ codes: item.code, countries: form.countries, currency: form.currency }) - + const response = await axios.post(route('products.compare'), { codes: item.code, countries: form.countries, currency: form.currency }) + products.value = response.data.products; countryHash.value = response.data.countryHash; console.log("TEST=", response.data); @@ -241,7 +245,22 @@ const showRow = async (item) => { response.isConfirmed && fetch() } }; +const onSelectCurrency = () => { + console.log('CURR', form.currency); + console.log('COEF', currencyCoef.value); + console.log('PROD', products.value); + if (products.value.length > 0) { + if (currencyCoef.value != 1.0) + products.value.map((product) => { product.salesPrice = product.salesPrice / currencyCoef.value }); + if (form.currency != 'EUR') currencyCoef.value = currencyHash.value[form.currency]; + else currencyCoef.value = 1.0; + + products.value = products.value.map((product) => { product.salesPrice = (product.salesPrice * currencyCoef.value).toFixed(2); return product }); + + console.log('PROD-NEW', products.value); + } +} const submit = () => { console.log('ITEM=', form); @@ -286,7 +305,8 @@ const submit = () => { Search in:
- +
@@ -295,20 +315,13 @@ const submit = () => {
- -
- Currency recalculation -
-
- -
- + +
- +
@@ -321,6 +334,14 @@ const submit = () => {
+
+ Currency recalculation +
+
+ +
+
Vysledky vyhladavania