Osclass forums

Development => Development => Topic started by: Liath on December 10, 2016, 12:10:19 am

Title: Use of Algolia Places
Post 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?
Title: Re: Use of Algolia Places
Post by: SteveJohnson on December 10, 2016, 01:11:46 am
I was once considering to implement Algolia search, but then went with sphinx. Algolia places looks interesting, i'm gonna check :) Thanks for telling...
Title: Re: Use of Algolia Places
Post by: Liath on December 10, 2016, 02:10:06 am
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



Title: Re: Use of Algolia Places
Post by: MkRahamath on December 10, 2016, 03:17:06 pm
Code are simple ? can you pleas share here..
Title: Re: Use of Algolia Places
Post by: Liath on December 10, 2016, 07:08:47 pm
After intergrating Algolia JavaScript and Stylesheet, i've done following steps...

At first, i've created a new file in my themes js folder

Quote from: ../oc-content/themes/THEMENAME/assets/js/places.js
Code: [Select]
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
Quote from: ../oc-content/themes/THEMENAME/footer.php
Code: [Select]
$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...

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.
Title: Re: Use of Algolia Places
Post by: MkRahamath on December 10, 2016, 07:14:53 pm
Thanks for the code.

I will try work with this.
Title: Re: Use of Algolia Places
Post by: Liath on December 10, 2016, 07:18:07 pm
If you have any suggestion, to work all well... please share here too :) i'm still working with it, to make it perfect
Title: Re: Use of Algolia Places
Post by: MkRahamath on December 10, 2016, 07:39:18 pm
Sure i do (Y)
Title: Re: Use of Algolia Places
Post by: webcity on January 20, 2017, 07:56:03 am
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
Title: Re: Use of Algolia Places
Post by: Liath on January 20, 2017, 06:36:32 pm
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.
Title: Re: Use of Algolia Places
Post by: MkRahamath on January 21, 2017, 01:23:19 am
How much it cost or free?
Title: Re: Use of Algolia Places
Post by: Liath on January 21, 2017, 01:34:32 am
all my plugins will be free
Title: Re: Use of Algolia Places
Post by: tito on January 21, 2017, 02:07:50 am
And are good plugins also :)
Title: Re: Use of Algolia Places
Post by: Liath on January 21, 2017, 02:57:03 am
And are good plugins also :)


thanks for compliment  ;D
Title: Re: Use of Algolia Places
Post by: webcity on January 21, 2017, 09:07:18 am
Fantastic! Thanks for all your efforts Liath, looking forward to the plugin release.

Many thanks,
Spencer
Title: Re: Use of Algolia Places
Post by: MkRahamath on January 21, 2017, 10:10:52 pm
all my plugins will be free

That's great and appreciated :)
Title: Re: Use of Algolia Places
Post by: leuname07 on May 08, 2019, 02:29:50 am
Hello,

I have osclass theme stela.

Can you help me to configure algolia places ?

Thank you.
Title: Re: Use of Algolia Places
Post by: warren mchugh on July 04, 2019, 04:15:46 pm

Hi, Can you please let us know the integration of the Algolia Places i would be glad to hear from you thanks.