Osclass forums
Development => Development => Topic started by: Liath on December 10, 2016, 12:10:19 am
-
Hey guys,
i'm just playing around with Algolia Places (https://community.algolia.com/places/) and try to implement to my theme. It's pretty easy to implement, but i need to adjust it a little bit more, to get the selected country etc...
I think its a good addition instead the locations management od OSClass, because there you dont need to enter the locations... What do you think, it's worth to give it a try?
-
I was once considering to implement Algolia search, but then went with sphinx. Algolia places looks interesting, i'm gonna check :) Thanks for telling...
-
it seems to be really easy to implement at all... for now all works fine
when i select a city, it change values for country and region too
-
Code are simple ? can you pleas share here..
-
After intergrating Algolia JavaScript and Stylesheet, i've done following steps...
At first, i've created a new file in my themes js folder
function loadPlaces(locale, country) {
var placesAutocomplete = places({
container: document.querySelector('#sCity'),
type: 'city',
language: locale,
countries: [country],
templates: {
value: function(suggestion) {
return suggestion.name;
}
}
});
placesAutocomplete.on('change', function resultSelected(e) {
var region = e.suggestion.administrative,
country = e.suggestion.countryCode.toUpperCase(),
parent = $('#sCountry').parent("div"),
button = parent.children("button");
if (region) { $("#sRegion").val(region); }
else { $("#sRegion").val(""); }
if (country) {
$("#sCountry").val(country);
$('#sCountry option[value='+country+']').attr('selected','selected'); //only needed for Material-Input
$(button).children('span.filter-option.pull-left').html($("#sCountry option:selected").text()); //only needed for Material-Input
}
});
}
then in footer.php
$countries = array();
foreach(osc_get_countries() as $v) { array_push($countries, "'".strtolower($v['pk_c_code']."'")); }
$countries = implode(", ", $countries);
//Doesnt work well, because you need the ISO 639-1 Country Code, not the first two letters of language code
$locale = explode("_", osc_current_user_locale());
$locale = $locale[0];
?>
...
...
<script>
$(document).ready(function(){
$("#sCountry").on("change", function(event){
var selCountry = $(this).val().toLowerCase();
loadPlaces("<?php echo $locale; ?>", (selCountry.length >=1 ? selCountry : "<?php echo $countries; ?>"));
});
loadPlaces("<?php echo $locale; ?>", "<?php echo $countries; ?>");
});
</script>
</body>
</html>
But... there are two problems left...
- The function is started when page is loaded, but doesnt working unless you are selecting a country
- Sometimes if you change the country, there are still citys from other countrys left
Maybe another developer has ideas for a better implementing of this function, to work all well
Edit:
If you are using the autocomplete from osclass, you must first disable it, otherwise the results will appear twice.
-
Thanks for the code.
I will try work with this.
-
If you have any suggestion, to work all well... please share here too :) i'm still working with it, to make it perfect
-
Sure i do (Y)
-
Hi,
This looks a great option :-). I'm looking to add it to my theme too. Has anyone managed to get it working OK that wouldn't mind sharing the coding?
Many thanks
-
I have solved all problems and made a plugin for this. I have to finish some other projects first, then i can upload it to the market.
-
How much it cost or free?
-
all my plugins will be free
-
And are good plugins also :)
-
And are good plugins also :)
thanks for compliment ;D
-
Fantastic! Thanks for all your efforts Liath, looking forward to the plugin release.
Many thanks,
Spencer
-
all my plugins will be free
That's great and appreciated :)
-
Hello,
I have osclass theme stela.
Can you help me to configure algolia places ?
Thank you.
-
Hi, Can you please let us know the integration of the Algolia Places i would be glad to hear from you thanks.