Post by webpie it. » Tue Aug 16, 2011 3:58 pm

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


Active Member

Posts

Joined
Mon Jan 31, 2011 7:28 pm

Post by webpie it. » Tue Aug 16, 2011 6:36 pm

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


Active Member

Posts

Joined
Mon Jan 31, 2011 7:28 pm

Post by threedonuts » Sun Sep 04, 2011 5:40 am

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>

Newbie

Posts

Joined
Sun Sep 04, 2011 5:39 am

Post by DaniellY » Fri Sep 09, 2011 3:11 pm

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 10:07 pm, edited 2 times in total.

Newbie

Posts

Joined
Thu Sep 08, 2011 4:45 pm

Post by perezosogato » Sun Sep 18, 2011 10: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

New member

Posts

Joined
Sun Jul 24, 2011 1:03 am

Post by perezosogato » Sun Sep 18, 2011 11: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 6130 times

geo_zone_form.jpg

here is the geo files i modified according the thread - geo_zone_form.jpg (119.44 KiB) Viewed 6130 times


New member

Posts

Joined
Sun Jul 24, 2011 1:03 am

Post by Gl4cier » Mon Sep 19, 2011 4:07 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..
Tried this and it doesn't work too (button and script?), any success with 1.5.1?

Newbie

Posts

Joined
Mon Sep 19, 2011 3:52 am

Post by perezosogato » Mon Sep 19, 2011 9:16 am

er... where is Q ?

New member

Posts

Joined
Sun Jul 24, 2011 1:03 am

Post by Yuki » Thu Sep 22, 2011 5:57 am

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
Newbie

Posts

Joined
Thu Aug 04, 2011 11:53 pm

Post by perezosogato » Thu Sep 22, 2011 9:38 am

I added each by each in about 10 mins

New member

Posts

Joined
Sun Jul 24, 2011 1:03 am

Post by sucotronic » Tue Oct 11, 2011 12:12 am

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;

Newbie

Posts

Joined
Tue Oct 11, 2011 12:09 am

Post by perezosogato » Tue Oct 11, 2011 12:34 am

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?

New member

Posts

Joined
Sun Jul 24, 2011 1:03 am

Post by sucotronic » Tue Oct 11, 2011 1:38 am

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.

Newbie

Posts

Joined
Tue Oct 11, 2011 12:09 am

Post by perezosogato » Tue Oct 11, 2011 10:15 am

hmmm....let me try on the localhost and then we will see...

New member

Posts

Joined
Sun Jul 24, 2011 1:03 am

Post by OSWorX » Tue Oct 11, 2011 2:44 pm

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)

Image


User avatar
Expert Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by markman-b » Tue Oct 11, 2011 9: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


Active Member

Posts

Joined
Wed Aug 24, 2011 7:13 pm

Post by jp1976 » Thu Nov 03, 2011 3:08 pm

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

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

New member

Posts

Joined
Mon Oct 31, 2011 12:01 am

Post by Qphoria » Thu Nov 03, 2011 10:21 pm

perezosogato wrote:er... where is Q ?
where should I be?

OpenCart 2.0.x Mod Update Info

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by sucotronic » Sat Nov 05, 2011 12:35 am

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.

Newbie

Posts

Joined
Tue Oct 11, 2011 12:09 am

Post by jp1976 » Sat Nov 12, 2011 4:49 am

mmm... i m not very sure how to hardcode this...
some direction?

New member

Posts

Joined
Mon Oct 31, 2011 12:01 am
Who is online

Users browsing this forum: No registered users and 10 guests