VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: rvbgnu on June 29, 2012, 00:37:17 AM

Title: How to change the countries order in the list for registration?
Post by: rvbgnu on June 29, 2012, 00:37:17 AM
Hi great VM community!

I want to sort the countries list for my main customers (Ireland, UK, USA, and other european countries). The Idea is to have first these main countries, and then the rest of the list. There is a field "ordering" in the table "_virtuemart_countries ", but i tried to put some values, with no effect.
Anyone has an idea on how to change this?

Probably a template override on editaddress.php, like in the post about the default country. Thanks raycarter!
http://forum.virtuemart.net/index.php?topic=97563.msg337782#new
Title: Re: How to change the countries order in the list for registration?
Post by: raycarter on July 02, 2012, 13:55:38 PM
HI,

I am in a hurry but someone else or you yourself with a bit of jquery can do this in the same layout.

just define an array containing ids of countries that you need to get on top. values should be in order :
then loop through them and place them on top.

THis is js code put it in the existing jquery ready event code on the page.





var countriestotop = new Array("56,57,102,203");
for (i=0; i<countriestotop.length ; i++){
if(i==0) jQuery('select#virtuemart_country_id option[value=countriestotop[i]]').append('select#virtuemart_country_id');
else
jQuery('select#virtuemart_country_id option[value=countriestotop[i]]').after('select#virtuemart_country_id li:eq(i-1)');

}


not tested.
Title: Re: How to change the countries order in the list for registration?
Post by: rvbgnu on July 04, 2012, 18:29:08 PM
Thanks RayCarter, I will try this and get back here with the result!
Title: Re: How to change the countries order in the list for registration?
Post by: MADmarion on November 26, 2012, 10:36:48 AM
Did this solution work for you?  Where did you put the code?

I cant solve this unfortunately.
Title: Re: How to change the countries order in the list for registration?
Post by: raycarter on November 26, 2012, 21:40:52 PM
It must work.

Copy this file : <siteroot>/components/com_virtuemart/views/user/edit_address.php

And place it under : <siteroot>/templates/<yourcurrenttemplate>/html/com_virtuemart/user/edit_address.php

And then at the top of the html code (outside the php tags) place the script

<script type="text/javascript">
var countriestotop = new Array("56,57,102,203"); //ids of countries that you need to get on top.
for (i=0; i<countriestotop.length ; i++){
if(i==0) jQuery('select#virtuemart_country_id option[value=countriestotop[i]]').append('select#virtuemart_country_id');
else
jQuery('select#virtuemart_country_id option[value=countriestotop[i]]').after('select#virtuemart_country_id li:eq(i-1)');
</script>


Test and reply.

EDIT: I am not sure f it worked for you or not. Just dont run away after you see something worked or didnt work for you, instead come and leave a reply here for others to know. had the first guy done that you wouldnt need to ask, if you do it, the next person wont ask.
The reason people dont reply is the reason developers dont wish to help anymore. We are a community and must help each other, give and take is the principle.


Title: Re: How to change the countries order in the list for registration?
Post by: MADmarion on December 05, 2012, 21:11:02 PM
Sorry for replying late. Had to fix many other issues in VM2 before I could try again to fix this one.

Unfortunately, your solution did not work for me.

I also tried the solution in this thread that modifies the php code, but whatever I try, country order stays the same (name/ASC).
http://forum.virtuemart.net/index.php?topic=101860.msg337881#msg337881

Really have no idea, why both solutions just dont change anything.
Title: Re: How to change the countries order in the list for registration?
Post by: raycarter on December 08, 2012, 13:34:55 PM
Change the $ sign with jQuery and see if it works. Also when the page loads, right click to open inspector and check the console tab for any errors.

If there is an error referring to the code i wrote report back. If all is Okay then pm me your website address and even FTP.
Title: Re: How to change the countries order in the list for registration?
Post by: ivan763 on January 14, 2013, 17:11:04 PM
Quote from: raycarter on November 26, 2012, 21:40:52 PM

EDIT: I am not sure f it worked for you or not. Just dont run away after you see something worked or didnt work for you, instead come and leave a reply here for others to know. had the first guy done that you wouldnt need to ask, if you do it, the next person wont ask.
The reason people dont reply is the reason developers dont wish to help anymore. We are a community and must help each other, give and take is the principle.

isn't working for me.

but i found the solution:
File:/components/com_virtuemart/assets/js/vmsite.js
after line 18 ( methods.update(this,dest,ids);  )
add:

$('#virtuemart_country_id option[value="176"]').attr('selected', 'selected');
$(this).each( function() { methods.update(this,dest)});

it's working for me.



Title: Re: How to change the countries order in the list for registration?
Post by: raycarter on January 16, 2013, 20:11:34 PM
Quote from: ivan763 on January 14, 2013, 17:11:04 PM
Quote from: raycarter on November 26, 2012, 21:40:52 PM

EDIT: I am not sure f it worked for you or not. Just dont run away after you see something worked or didnt work for you, instead come and leave a reply here for others to know. had the first guy done that you wouldnt need to ask, if you do it, the next person wont ask.
The reason people dont reply is the reason developers dont wish to help anymore. We are a community and must help each other, give and take is the principle.

isn't working for me.

but i found the solution:
File:/components/com_virtuemart/assets/js/vmsite.js
after line 18 ( methods.update(this,dest,ids);  )
add:

$('#virtuemart_country_id option[value="176"]').attr('selected', 'selected');
$(this).each( function() { methods.update(this,dest)});

it's working for me.





Did you try what i wrote above?

Quote from: raycarter on December 08, 2012, 13:34:55 PM
Change the $ sign with jQuery and see if it works. Also when the page loads, right click to open inspector and check the console tab for any errors.

If there is an error referring to the code i wrote report back. If all is Okay then pm me your website address and even FTP.
Title: Re: How to change the countries order in the list for registration?
Post by: softpill on October 01, 2013, 18:21:42 PM
Follow this tutorial for a quick hack in changing the countries order

http://blog.softpill.eu/how-to-change-countries-order-on-virtuemart/ (http://blog.softpill.eu/how-to-change-countries-order-on-virtuemart/)

hope will helps