Community Forums

[MOD] GeoZone - Add All Countries Button

Community created contributions & mods for OpenCart 1.x

Re: [MOD] GeoZone - Add All Countries Button

Postby webpie it. » Tue Aug 16, 2011 7:58 am

Ok so trying to do this for 1.5.0.5

Trying to ad the world to a gwo zone, i did succesfully use this for 1.4.9.3 a while back as you will see above.

The code i'm using is taken from above in two places:


Find:
CODE: SELECT ALL
Code: Select all
<a onclick="addGeoZone();" class="button"><span><?php echo $button_utton_add_geo_zone; ?></span></a>


After, add:
CODE: SELECT ALL
Code: Select all
<a onclick="addAllGeoZones();" class="button"><span>Add All Countries</span></a>


(This fixes the button styling)

Find:
CODE: SELECT ALL
Code: Select all
function addGeoZone() {



THIS IS THE CORRECTION FROM TONNAER

(I changed the fix a bit to cut down on the ajax requests (calling for each of the 180+ countries to get their zones was killing my browser , so the new button code of IBBoard is fine , and the code to place at the end of the page becomes:)


Before, add:
Code: Select all
<script type="text/javascript"><!--
function addAllGeoZones() {
<?php foreach ($countries as $country) { ?>
    html  = '<tbody id="zone_to_geo_zone_row' + zone_to_geo_zone_row + '">';
    html += '<tr>';
     html += '<td class="left"><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&token=<?php echo $token; ?>&country_id=\' + this.value + \'&zone_id=0\');">';
     html += '<option value="<?php echo $country['country_id']; ?>"><?php echo addslashes($country['name']); ?></option>';
    html += '</select></td>';
     html += '<td class="left"><select name="zone_to_geo_zone[' + zone_to_geo_zone_row + '][zone_id]" id="zone' + zone_to_geo_zone_row + '"><option value="0">All zones</option></select></td>';
     html += '<td class="left"><a onclick="$(\'#zone_to_geo_zone_row' + zone_to_geo_zone_row + '\').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>';
   
    html += '</tr>';
    html += '</tbody>';

    $('#zone_to_geo_zone > tfoot').before(html);
   
    zone_to_geo_zone_row++;
    <?php } ?>
}
//--></script>



At the moment though, the button does nothing when clicked?

I don;t like the SQL methods above as it's not usable for a client etc...

Can anyone try to help me fix this for 1.5.0.5 as i was under the impression that this hadn't changed since 1.4x?

Thanks Guys!

Chris
Regards

Chris
webpie it.
 
Posts: 374
Joined: Mon Jan 31, 2011 11:28 am

Re:SOLVED [MOD] GeoZone - Add All Countries Button

Postby webpie it. » Tue Aug 16, 2011 10:36 am

Solved by Jcsmithy! as usual!

everything above is correct accept:

Before:
$('#zone_to_geo_zone > tfoot').before(html);

After:
$('#zone-to-geo-zone > tfoot').before(html);

Just the dashes need to change for 1.5x

cHRIS
Regards

Chris
webpie it.
 
Posts: 374
Joined: Mon Jan 31, 2011 11:28 am

Re: [MOD] GeoZone - Add All Countries Button

Postby threedonuts » Sat Sep 03, 2011 9:40 pm

Trying to use this code on v1.5.1. No go, even with the underscore and dash fix in the above post. I have the button, but nothing happens when clicked. Anyone had success? This should really be a standard feature!

Edit: Fixed...I did a replace all the first time since there were several occurences of $('#zone_to_geo_zone > tfoot').before(html);

Here's the working script for v1.5.1:

Code: Select all
<script type="text/javascript"><!--
function addAllGeoZones() {
<?php foreach ($countries as $country) { ?>
    html  = '<tbody id="zone_to_geo_zone_row' + zone_to_geo_zone_row + '">';
    html += '<tr>';
     html += '<td class="left"><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&token=<?php echo $token; ?>&country_id=\' + this.value + \'&zone_id=0\');">';
     html += '<option value="<?php echo $country['country_id']; ?>"><?php echo addslashes($country['name']); ?></option>';
    html += '</select></td>';
     html += '<td class="left"><select name="zone_to_geo_zone[' + zone_to_geo_zone_row + '][zone_id]" id="zone' + zone_to_geo_zone_row + '"><option value="0">All zones</option></select></td>';
     html += '<td class="left"><a onclick="$(\'#zone_to_geo_zone_row' + zone_to_geo_zone_row + '\').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>';
   
    html += '</tr>';
    html += '</tbody>';

    $('#zone-to-geo-zone > tfoot').before(html);
   
    zone_to_geo_zone_row++;
    <?php } ?>
}
//--></script>
threedonuts
 
Posts: 1
Joined: Sat Sep 03, 2011 9:39 pm

Re: [MOD] GeoZone - Add All Countries Button

Postby DaniellY » Fri Sep 09, 2011 7:11 am

threedonuts wrote:Trying to use this code on v1.5.1. No go, even with the underscore and dash fix in the above post. I have the button, but nothing happens when clicked. Anyone had success? This should really be a standard feature!

Edit: Fixed...I did a replace all the first time since there were several occurences of $('#zone_to_geo_zone > tfoot').before(html);

Here's the working script for v1.5.1:

Code: Select all
<script type="text/javascript"><!--
function addAllGeoZones() {
<?php foreach ($countries as $country) { ?>
    html  = '<tbody id="zone_to_geo_zone_row' + zone_to_geo_zone_row + '">';
    html += '<tr>';
     html += '<td class="left"><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&token=<?php echo $token; ?>&country_id=\' + this.value + \'&zone_id=0\');">';
     html += '<option value="<?php echo $country['country_id']; ?>"><?php echo addslashes($country['name']); ?></option>';
    html += '</select></td>';
     html += '<td class="left"><select name="zone_to_geo_zone[' + zone_to_geo_zone_row + '][zone_id]" id="zone' + zone_to_geo_zone_row + '"><option value="0">All zones</option></select></td>';
     html += '<td class="left"><a onclick="$(\'#zone_to_geo_zone_row' + zone_to_geo_zone_row + '\').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>';
   
    html += '</tr>';
    html += '</tbody>';

    $('#zone-to-geo-zone > tfoot').before(html);
   
    zone_to_geo_zone_row++;
    <?php } ?>
}
//--></script>

Oh, thanks for the working code! i has already started to worry about that..
Last edited by DaniellY on Mon Jun 18, 2012 2:07 pm, edited 2 times in total.
DaniellY
 
Posts: 4
Joined: Thu Sep 08, 2011 8:45 am

Re: [MOD] GeoZone - Add All Countries Button

Postby perezosogato » Sun Sep 18, 2011 2:15 am

DaniellY wrote:
threedonuts wrote:Trying to use this code on v1.5.1. No go, even with the underscore and dash fix in the above post. I have the button, but nothing happens when clicked. Anyone had success? This should really be a standard feature!

Edit: Fixed...I did a replace all the first time since there were several occurences of $('#zone_to_geo_zone > tfoot').before(html);

Here's the working script for v1.5.1:

Code: Select all
<script type="text/javascript"><!--
function addAllGeoZones() {
<?php foreach ($countries as $country) { ?>
    html  = '<tbody id="zone_to_geo_zone_row' + zone_to_geo_zone_row + '">';
    html += '<tr>';
     html += '<td class="left"><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&token=<?php echo $token; ?>&country_id=\' + this.value + \'&zone_id=0\');">';
     html += '<option value="<?php echo $country['country_id']; ?>"><?php echo addslashes($country['name']); ?></option>';
    html += '</select></td>';
     html += '<td class="left"><select name="zone_to_geo_zone[' + zone_to_geo_zone_row + '][zone_id]" id="zone' + zone_to_geo_zone_row + '"><option value="0">All zones</option></select></td>';
     html += '<td class="left"><a onclick="$(\'#zone_to_geo_zone_row' + zone_to_geo_zone_row + '\').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>';
   
    html += '</tr>';
    html += '</tbody>';

    $('#zone-to-geo-zone > tfoot').before(html);
   
    zone_to_geo_zone_row++;
    <?php } ?>
}
//--></script>

Oh, thanks for the working code! i has already started to worry about that..



Hi DaniellY,

does it work on the v1.50 ? Or need i upgrade to the v1.5.1
perezosogato
 
Posts: 85
Joined: Sat Jul 23, 2011 5:03 pm

Re: Re:SOLVED [MOD] GeoZone - Add All Countries Button

Postby perezosogato » Sun Sep 18, 2011 3:30 am

webpie it. wrote:Solved by Jcsmithy! as usual!

everything above is correct accept:

Before:
$('#zone_to_geo_zone > tfoot').before(html);

After:
$('#zone-to-geo-zone > tfoot').before(html);

Just the dashes need to change for 1.5x

cHRIS


hi webpie.it

i am using v1.50, which is upgraded from v1.4.9.3.
though there is a add all countries button, but also find the below thing,
when i click "add all countries" button, not work....please find the attachment
Attachments
bottom_word.jpg
here is the message i got from the admin of CSM
bottom_word.jpg (106.66 KiB) Viewed 1913 times
geo_zone_form.jpg
here is the geo files i modified according the thread
geo_zone_form.jpg (119.44 KiB) Viewed 1913 times
perezosogato
 
Posts: 85
Joined: Sat Jul 23, 2011 5:03 pm

Re: [MOD] GeoZone - Add All Countries Button

Postby Gl4cier » Sun Sep 18, 2011 8:07 pm

DaniellY wrote:
threedonuts wrote:Trying to use this code on v1.5.1. No go, even with the underscore and dash fix in the above post. I have the button, but nothing happens when clicked. Anyone had success? This should really be a standard feature!

Edit: Fixed...I did a replace all the first time since there were several occurences of $('#zone_to_geo_zone > tfoot').before(html);

Here's the working script for v1.5.1:

Code: Select all
<script type="text/javascript"><!--
function addAllGeoZones() {
<?php foreach ($countries as $country) { ?>
    html  = '<tbody id="zone_to_geo_zone_row' + zone_to_geo_zone_row + '">';
    html += '<tr>';
     html += '<td class="left"><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&token=<?php echo $token; ?>&country_id=\' + this.value + \'&zone_id=0\');">';
     html += '<option value="<?php echo $country['country_id']; ?>"><?php echo addslashes($country['name']); ?></option>';
    html += '</select></td>';
     html += '<td class="left"><select name="zone_to_geo_zone[' + zone_to_geo_zone_row + '][zone_id]" id="zone' + zone_to_geo_zone_row + '"><option value="0">All zones</option></select></td>';
     html += '<td class="left"><a onclick="$(\'#zone_to_geo_zone_row' + zone_to_geo_zone_row + '\').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>';
   
    html += '</tr>';
    html += '</tbody>';

    $('#zone-to-geo-zone > tfoot').before(html);
   
    zone_to_geo_zone_row++;
    <?php } ?>
}
//--></script>

Oh, thanks for the working code! i has already started to worry about that..


Tried this and it doesn't work too (button and script?), any success with 1.5.1?
Gl4cier
 
Posts: 5
Joined: Sun Sep 18, 2011 7:52 pm

Re: [MOD] GeoZone - Add All Countries Button

Postby perezosogato » Mon Sep 19, 2011 1:16 am

er... where is Q ?
perezosogato
 
Posts: 85
Joined: Sat Jul 23, 2011 5:03 pm

Re: [MOD] GeoZone - Add All Countries Button

Postby Yuki » Wed Sep 21, 2011 9:57 pm

Brad wrote:A quicker way if you don't mind running SQL direclty on the database is to use the following SQL

1. Find the geo_zone_id for your "Rest of the world" FGeo Zone
Code: Select all
SELECT geo_zone_id FROM `geo_zone` WHERE name = 'Rest of the world'

2. Then take this number (this example uses 6) and replace the number 6 in the following SQL
Code: Select all
INSERT into zone_to_geo_zone (country_id, geo_zone_id)
   SELECT country_id, 6
   FROM country

Done!


I wasn't able to get the code provided to work in this thread so I used Brad's MySQL solution and it worked ^ ^ (I just need to remove US zone off the list). Thanks!
User avatar
Yuki
 
Posts: 11
Joined: Thu Aug 04, 2011 3:53 pm

Re: [MOD] GeoZone - Add All Countries Button

Postby perezosogato » Thu Sep 22, 2011 1:38 am

I added each by each in about 10 mins
perezosogato
 
Posts: 85
Joined: Sat Jul 23, 2011 5:03 pm

Re: [MOD] GeoZone - Add All Countries Button

Postby sucotronic » Mon Oct 10, 2011 4:12 pm

Using mysql shell it only takes seconds. First you have to create a Geo Zone with the description "Rest of the world", and then execute the following from the Mysql CLI:

Code: Select all
delimiter $$
CREATE PROCEDURE myProc()
  READS SQL DATA
BEGIN
  DECLARE geo_zzone INT;
  DECLARE count_countries INT;
  DECLARE country_insert INT;

  SELECT `geo_zone_id` INTO geo_zzone
  FROM `geo_zone`
  WHERE `description` LIKE "Rest of the world";

  SELECT count(`country`.`name`) INTO `count_countries` FROM `country`
  WHERE `country`.`country_id` NOT IN (SELECT `zone_to_geo_zone`.`country_id` FROM `zone_to_geo_zone`);

  WHILE (count_countries > 0) DO
    SELECT country.country_id INTO country_insert FROM country
    WHERE country.country_id NOT IN (SELECT zone_to_geo_zone.country_id FROM zone_to_geo_zone) LIMIT 1;

    INSERT INTO `zone_to_geo_zone` VALUES (NULL, country_insert, '0', geo_zzone, NOW(), DATE(0));

    SELECT count(name) INTO count_countries FROM country
    WHERE country_id NOT IN (SELECT country_id FROM zone_to_geo_zone);
  END WHILE;

END$$

delimiter ;

 call myProc();
drop procedure myProc;
sucotronic
 
Posts: 4
Joined: Mon Oct 10, 2011 4:09 pm

Re: [MOD] GeoZone - Add All Countries Button

Postby perezosogato » Mon Oct 10, 2011 4:34 pm

sucotronic wrote:Using mysql shell it only takes seconds. First you have to create a Geo Zone with the description "Rest of the world", and then execute the following from the Mysql CLI:

Code: Select all
delimiter $$
CREATE PROCEDURE myProc()
  READS SQL DATA
BEGIN
  DECLARE geo_zzone INT;
  DECLARE count_countries INT;
  DECLARE country_insert INT;

  SELECT `geo_zone_id` INTO geo_zzone
  FROM `geo_zone`
  WHERE `description` LIKE "Rest of the world";

  SELECT count(`country`.`name`) INTO `count_countries` FROM `country`
  WHERE `country`.`country_id` NOT IN (SELECT `zone_to_geo_zone`.`country_id` FROM `zone_to_geo_zone`);

  WHILE (count_countries > 0) DO
    SELECT country.country_id INTO country_insert FROM country
    WHERE country.country_id NOT IN (SELECT zone_to_geo_zone.country_id FROM zone_to_geo_zone) LIMIT 1;

    INSERT INTO `zone_to_geo_zone` VALUES (NULL, country_insert, '0', geo_zzone, NOW(), DATE(0));

    SELECT count(name) INTO count_countries FROM country
    WHERE country_id NOT IN (SELECT country_id FROM zone_to_geo_zone);
  END WHILE;

END$$

delimiter ;

 call myProc();
drop procedure myProc;


will it be dismissed once upgrade to a higher version OC?
perezosogato
 
Posts: 85
Joined: Sat Jul 23, 2011 5:03 pm

Re: [MOD] GeoZone - Add All Countries Button

Postby sucotronic » Mon Oct 10, 2011 5:38 pm

Is my first experience with Opencart, but the normal way to upgrade shouldn't affect this, because it does the same as if you click the countries one by one.
sucotronic
 
Posts: 4
Joined: Mon Oct 10, 2011 4:09 pm

Re: [MOD] GeoZone - Add All Countries Button

Postby perezosogato » Tue Oct 11, 2011 2:15 am

hmmm....let me try on the localhost and then we will see...
perezosogato
 
Posts: 85
Joined: Sat Jul 23, 2011 5:03 pm

Re: [MOD] GeoZone - Add All Countries Button

Postby OSWorX » Tue Oct 11, 2011 6:44 am

perezosogato wrote:will it be dismissed once upgrade to a higher version OC?

Normally updates should not touch any existing tables in the database.
Except the case, the table layout will be changed again (which can happen - you never will know what Daniel will do)
EU-Buttonlösung EU-Cookies OpenCart Rechtskonform
LiveSupport (Chat) Deutsches OpenCart / OCIE Forum
http://osworx.net :: Installation & Update Services for OpenCart, Custom Development
Common modules - Payment modules - Shipping modules - Dt. Sprachpaket
User avatar
OSWorX
Global Moderator
 
Posts: 1879
Joined: Mon Jan 11, 2010 2:52 pm
Location: Austria

Re: [MOD] GeoZone - Add All Countries Button

Postby markman-b » Tue Oct 11, 2011 1:02 pm

I added them all manually. It gives me a warm feeling that even people from Gabon and Gambia can buy my products now. Do they have glassfiber internet there??? ?
OC version 1.5.4.1
markman-b
 
Posts: 233
Joined: Wed Aug 24, 2011 11:13 am

Re: [MOD] GeoZone - Add All Countries Button

Postby jp1976 » Thu Nov 03, 2011 7:08 am

hi all. if i want some buttons like this, how i can?

Europe -- USA&Canada -- Asia -- Africa
jp1976
 
Posts: 34
Joined: Sun Oct 30, 2011 4:01 pm

Re: [MOD] GeoZone - Add All Countries Button

Postby Qphoria » Thu Nov 03, 2011 2:21 pm

perezosogato wrote:er... where is Q ?


where should I be?
Image Image
Donate!|OpenCart Basics|GeoZones
Help me get more development cloud storage - Click Here to get DropBox
User avatar
Qphoria
Administrator
 
Posts: 18197
Joined: Mon Jul 21, 2008 7:02 pm
Donate to Qphoria

Re: [MOD] GeoZone - Add All Countries Button

Postby sucotronic » Fri Nov 04, 2011 4:35 pm

jp1976 wrote:hi all. if i want some buttons like this, how i can?

Europe -- USA&Canada -- Asia -- Africa


Best way... hard code it directly in the php file. I know isn't elegant, but is easy and works.
sucotronic
 
Posts: 4
Joined: Mon Oct 10, 2011 4:09 pm

Re: [MOD] GeoZone - Add All Countries Button

Postby jp1976 » Fri Nov 11, 2011 8:49 pm

mmm... i m not very sure how to hardcode this...
some direction?
jp1976
 
Posts: 34
Joined: Sun Oct 30, 2011 4:01 pm

PreviousNext

Return to Free Contributions

Who is online

Users browsing this forum: No registered users and 8 guests

Hosted by Arvixe Web Hosting