By Michael Stanek on Wednesday, 23 March 2022
Posted in General Issues
Replies 10
Likes 0
Views 706
Votes 0
Hi Stackideas, we implemented a simple Geolocation in the checkout, but in order to do so, we needed to alter some core files which is obviously not a good idea in longterm. I want to ask you how much it would cost to implement this as a Payplans feature as preselecting the country would improve the UX for everyone.

I will describe what we did:

1) we changed administrator/components/com_payplans/themes/default/helpers/form/country.php, line 35. Changed the values of the select options from $country->country_id to $country->isocode2 so the HTML output is e.g. <option value="MY">Malaysia</option> instead of a number <option value="150">Malaysia</option>. The problem with this change is that geolocation works just fine, but VAT ID stops working. It requires your edits as you know what files might be affected by this.

2) we added a piece of JS code that takes care of geolocation into components/com_payplans/themes/wireframe/checkout/default/default.js. Don't wanna paste it here and clutter the message, but I will provide you with it when needed.


Let me know what you think. Again, I emphasize we are happy to pay for the development. Michael
Hi, just a friendly reminder that this has been waiting for a reply for a few days. My fault probably - I posted it into a wrong category. Thanks a lot. Michael
·
Monday, 28 March 2022 21:12
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Micheal,

1) we changed administrator/components/com_payplans/themes/default/helpers/form/country.php, line 35. Changed the values of the select options from $country->country_id to $country->isocode2 so the HTML output is e.g. <option value="MY">Malaysia</option> instead of a number <option value="150">Malaysia</option>. The problem with this change is that geolocation works just fine, but VAT ID stops working. It requires your edits as you know what files might be affected by this.
Yes, if you change the country field it will not work anywhere where PayPlans using this.

2) we added a piece of JS code that takes care of geolocation into components/com_payplans/themes/wireframe/checkout/default/default.js. Don't wanna paste it here and clutter the message, but I will provide you with it when needed.
Can you provide us with the changes you did, so we will check it and let you know further about this.

Looking forward to your response.
·
Tuesday, 29 March 2022 11:08
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Manisha,

2) we added a piece of JS code

This is the JS code. Very simple, work like a charm, but the country select option values need to be iso2. What is your suggestion?

(async() => {
const res = await fetch("https://freegeoip.app/json/");
const json = await res.json();
document.getElementById("preference[business_country]").value = json.country_code;
})();
·
Tuesday, 29 March 2022 18:41
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Micheal,

Thank you for sharing the details. Please refer followings.

1. You don't need to change the country field to use the iso code. Please revert the changes mentioned in this file. administrator/components/com_payplans/themes/default/helpers/form/country.php, line 35

2. Then try the below-mentioned js code and see how it goes for you.

(async() => {
const res = await fetch("https://freegeoip.app/json/");
const json = await res.json();

var country_code = json.country_code;

PayPlans.ajax('site/views/checkout/getCountryFromVatNo', {
"isoCode2": country_code
})
.done(function(countryId) {
// auto select the country if vat number consist the country isocode
if (countryId) {
$('[data-pp-company-country]').val(countryId);
$('[data-pp-company-country]').trigger('change');
}
});
})();


Note: Try this solution on the site where we perform a customization for you.
Remember to do these changes with template overriding, so your changes will not be lost on the upgrade.

Thank you for understanding!
·
Wednesday, 30 March 2022 11:21
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Manisha. You guys are geniuses! Thanks a lot. Works like a charm. Please issue an invoice and let me know the price. Thanks a lot.
·
Wednesday, 30 March 2022 13:55
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Micheal,

You're most welcome.

Hey Manisha. You guys are geniuses! Thanks a lot. Works like a charm. Please issue an invoice and let me know the price. Thanks a lot.

I've just added a tweak in your existing JS code to make it work.

And thank you for your kind offer
You can use the 'Buy Us Coffee' form on this page.

If you don't mind and if it doesn't take too much of your time, is it possible for you to post up a review or give us some rating for Payplans at Joomla! Extensions Directory https://extensions.joomla.org/extension/payplans. This will really help motivate the team and will allow us to further improve our service as we move along.

Thank you for understanding!
·
Wednesday, 30 March 2022 14:49
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Manisha, by a "tweak", you mean what file exactly? The default.js in our tmpl overrides? Will buy you coffee, will give your JED rating. Thanks :-)
·
Wednesday, 30 March 2022 15:59
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Micheal,

Hi Manisha, by a "tweak", you mean what file exactly? The default.js in our tmpl overrides?

The js code you shared with us for file components/com_payplans/themes/wireframe/checkout/default/default.js..
As per the changes you shared here: https://stackideas.com/forums/country-geo-location#reply-572579

Will buy you coffee, will give your JED rating. Thanks :-)

Thank you.

Let me know if you will have any queries.
·
Wednesday, 30 March 2022 16:32
·
0 Likes
·
0 Votes
·
0 Comments
·
Got it. Sorry, got confused. Sending coffees .-)
·
Thursday, 31 March 2022 09:32
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Micheal,

No Problem. Thank you for the coffee.
·
Thursday, 31 March 2022 11:05
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post