Page 1 of 5

[MOD] GeoZone - Add All Countries Button

Posted: Sun Nov 01, 2009 2:28 am
by Qphoria
For those who want to make a "Rest of the world" zone, that has all zones except a few, I made this button that will allow you to easily do this. I Created a new javascript button next to "Add Geo Zone" called "Add All Countries".

This basically adds a new geozone for each country and autoselects each individual country. Then you can simply remove the countries you don't want to be part of that geozone and save.

1. EDIT: admin/view/template/localisation/geo_zone_form.tpl

2. FIND:

Code: Select all

<a onclick="addGeoZone();" class="button"><span class="button_left button_insert"></span><span class="button_middle"><?php echo $button_add_geo_zone; ?></span><span class="button_right"></span></a>
3. AFTER, ADD:

Code: Select all

<a onclick="addAllGeoZones();" class="button"><span class="button_left button_insert"></span><span class="button_middle">Add All Countries</span><span class="button_right"></span></a>
4. AT THE BOTTOM OF THAT FILE, ADD:

Code: Select all

<script type="text/javascript">
function addAllGeoZones() {
    <?php foreach ($countries as $k => $v) { ?>
    html  = '<table class="green" id="zone_to_geo_zone_row' + zone_to_geo_zone_row + '">';
    html += '<tr>';
    html += '<td><?php echo $entry_country; ?><br /><select name="zone_to_geo_zone[' + zone_to_geo_zone_row + '][country_id]" id="country' + zone_to_geo_zone_row + '" onchange="$(\'#zone' + zone_to_geo_zone_row + '\').load(\'index.php?route=localisation/geo_zone/zone&country_id=\' + this.value + \'&zone_id=0\');">';
    <?php foreach ($countries as $country) { ?>
    html += '<option value="<?php echo $country['country_id']; ?>" <?php echo (($country['country_id']) == $k+1) ? 'selected="selected"' : ''; ?>><?php echo addslashes($country['name']); ?></option>';
    <?php } ?>   
    html += '</select></td>';
    html += '<td rowspan="2"><a onclick="$(\'#zone_to_geo_zone_row' + zone_to_geo_zone_row + '\').remove();" class="button"><span class="button_left button_delete"></span><span class="button_middle"><?php echo $button_remove; ?></span><span class="button_right"></span></a></td>';
    html += '</tr>';
    html += '<tr>';
    html += '<td><?php echo $entry_zone; ?><br /><select name="zone_to_geo_zone[' + zone_to_geo_zone_row + '][zone_id]" id="zone' + zone_to_geo_zone_row + '"></select></td>';
    html += '</tr>';
    html += '</table>';
    $('#zone_to_geo_zone').append(html);
        
    $('#zone' + zone_to_geo_zone_row).load('index.php?route=localisation/geo_zone/zone&country_id=' + $('#country' + zone_to_geo_zone_row).attr('value') + '&zone_id=0');
    
    zone_to_geo_zone_row++;
    <?php } ?>
}
</script>
Now insert a new GeoZone. Click the "Add All Countries" button... (wait like 5-10secs as it is very system intensive) Then you should see every country added. Remove the ones you don't want.

Re: [MOD] GeoZone - Add All Countries Button

Posted: Sun Nov 01, 2009 3:07 am
by amplifywebdesign
This is fantastic. Is there any way you can modify this so I can add all regions from a country?

Re: [MOD] GeoZone - Add All Countries Button

Posted: Sun Nov 01, 2009 3:22 am
by Qphoria
It's already implied.

Re: [MOD] GeoZone - Add All Countries Button

Posted: Sun Nov 01, 2009 9:40 pm
by amplifywebdesign
Qphoria wrote:It's already implied.
Where? I need it so I can edit out some counties

Re: [MOD] GeoZone - Add All Countries Button

Posted: Mon Nov 02, 2009 12:30 am
by Qphoria
Oh you mean you want to add all zones as well? That would probably crash your browser. To load all countries with each zone individually.

This is more designed for the "rest of the world" where people create 1 zone with the few zones they want at a cheap price. and then they create another zone named "Worldwide" and use this button to add all countries and all zones. Then they can simply remove the few countries they don't want.

If you just want to edit out certain zones of a country, it is not likely you need to do that to ALL countries, so you can do that one manually in its own zone

Re: [MOD] GeoZone - Add All Countries Button

Posted: Mon Nov 02, 2009 10:49 pm
by amplifywebdesign
Sorry, I must not be explaining myself well - basically I want to add all Zones from the UK, and then be able to manually remove a couple of them.

I tried doing this by changing the select form to a multi -select:
Image


but it doesn't remember the multiple values :-(

Re: [MOD] GeoZone - Add All Countries Button

Posted: Fri Nov 27, 2009 8:01 am
by deeve
What a fantastic lifesaver this script was! I was about 1/4 way through manually entering all zones - doh!

Much appreciated, Q!

Re: [MOD] GeoZone - Add All Countries Button

Posted: Sat Dec 05, 2009 6:13 pm
by dramony
amplifywebdesign wrote:Sorry, I must not be explaining myself well - basically I want to add all Zones from the UK, and then be able to manually remove a couple of them.

I tried doing this by changing the select form to a multi -select:
Image


but it doesn't remember the multiple values :-(
--------------------------

just want to follow up on amplifywebdesign's post...
thanks.

Re: [MOD] GeoZone - Add All Countries Button

Posted: Sun Dec 06, 2009 12:43 am
by amplifywebdesign
dramony wrote: just want to follow up on amplifywebdesign's post...
I doubt I will get a reply. I just did it the long way in the end, took 15 minutes.

Re: [MOD] GeoZone - Add All Countries Button

Posted: Tue Dec 22, 2009 2:17 am
by steamcrow
Worked like a charm.

Thank you very much for doing this. Much, much easier and full of awesome.

Re: [MOD] GeoZone - Add All Countries Button

Posted: Thu Feb 04, 2010 3:06 am
by fireatwire
Doesn't work for me in V 1.4, what do I have to change?
Thanks

Re: [MOD] GeoZone - Add All Countries Button

Posted: Fri Feb 05, 2010 5:15 pm
by asg333
Hi,

Trying to implement in 1.4, but the code seems to be different. Has anybody done this for 1.4?

Thank you!

Adam

Re: [MOD] GeoZone - Add All Countries Button

Posted: Tue Feb 09, 2010 8:52 am
by whatwhat
I've also got 1.4 and really keen to use this.

Thanks
John

Re: [MOD] GeoZone - Add All Countries Button

Posted: Tue Feb 09, 2010 12:57 pm
by Qphoria
I'll see about updating it

Re: [MOD] GeoZone - Add All Countries Button

Posted: Mon Mar 15, 2010 8:51 am
by ulyssesnz
Hi Q,

I have read your post regarding the mod for adding a Geo Zone called "Rest of The World" i.e. add all countries and then remove the ones you don't want to be in this Zone because you have them listed individually.

http://forum.opencart.com/viewtopic.php ... 512#p51581

However, I understand that this mod does not work for OC v1.4.0

When will this be available?

This would be of great assistance.

Ulysses NZ

Re: [MOD] GeoZone - Add All Countries Button

Posted: Wed Apr 28, 2010 7:38 am
by dragonfly
Hi Q
I also think that having this available in the latest version of OC would be very useful indeed!
Just wondering how other people manage this, for example in 1.4.7?

Thanks in advance for your help! :)

Rachel

Re: [MOD] GeoZone - Add All Countries Button

Posted: Sat Sep 11, 2010 5:47 pm
by mmijangos
For OC 1.4.8 AT THE BOTTOM OF THAT FILE, ADD:

Code: Select all

<script type="text/javascript">
function addAllGeoZones() {
<?php foreach ($countries as $k => $v) { ?>
    html  = '<table class="green" id="zone_to_geo_zone_row' + zone_to_geo_zone_row + '">';
    html += '<tr>';
    html += '<td><?php echo $entry_country; ?><br /><select name="zone_to_geo_zone[' + zone_to_geo_zone_row + '][country_id]" id="country' + zone_to_geo_zone_row + '" onchange="$(\'#zone' + zone_to_geo_zone_row + '\').load(\'index.php?route=localisation/geo_zone/zone&country_id=\' + this.value + \'&zone_id=0\');">';
    
    <?php foreach ($countries as $country) { ?>
    html += '<option value="<?php echo $country['country_id']; ?>" <?php echo (($country['country_id']) == $k+1) ? 'selected="selected"' : ''; ?>><?php echo addslashes($country['name']); ?></option>';
    <?php } ?>   
    html += '</select></td>';
    html += '<td rowspan="2">
    <a onclick="$(\'#zone_to_geo_zone_row' + zone_to_geo_zone_row + '\').remove();" class="button"><span class="button_left button_delete"></span><span class="button_middle"><?php echo $button_remove; ?></span><span class="button_right"></span></a></td>';
    
    html += '</tr>';
    html += '<tr>';
    html += '<td><?php echo $entry_zone; ?><br /><select name="zone_to_geo_zone[' + zone_to_geo_zone_row + '][zone_id]" id="zone' + zone_to_geo_zone_row + '"></select></td>';
    html += '</tr>';
    
    html += '</table>';

    $('#zone_to_geo_zone').append(html);
    $('#zone' + zone_to_geo_zone_row).load('index.php?route=localisation/geo_zone/zone&country_id=' + $('#country' + zone_to_geo_zone_row).attr('value') + '&zone_id=0');
   
    zone_to_geo_zone_row++;
    <?php } ?>
}
</script>

Re: [MOD] GeoZone - Add All Countries Button

Posted: Tue Sep 14, 2010 1:27 am
by PaulineNMU
I tried this in 1.4.8 and it crashed Mozilla after endlessly adding countries for two minutes. Any suggestions?

Re: [MOD] GeoZone - Add All Countries Button

Posted: Tue Sep 14, 2010 1:54 am
by Qphoria
yea.. it is very system intensive and weaker PCs or browsers may have an issue with it.

Re: [MOD] GeoZone - Add All Countries Button

Posted: Tue Sep 14, 2010 2:59 am
by PaulineNMU
Yeah.. I understand that.. Unfortunately, I'm running a 3.0 quad-core with 4 gigs of RAM and I tried it on FireFox and IE and it crashed both. I let it sit for a good 5 minutes and I think it just kept endlessly looping or something. That was using the original code. The new code listed at the bottom of the thread just gives a script error and does nothing.

It's not the end of the world, I put them in manually and increased my World Geography knowledge in the process, but I have another cart to put together next week and I'm gonna need to enter them all again.

Either way, I appreciate the contribution :) Even if my system doesn't seem to like it.

(FYI, trying to use this with Zone Shipping Plus - would it be super hard to just add an All Other Zones button to that extension?)