Post by Qphoria » Tue Sep 14, 2010 3:18 am

it needs to loop 280ish times for all the countries. Define crash? it should sit for about 30 secs unresponsive and then come back

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 PaulineNMU » Tue Sep 14, 2010 4:08 am

In Firefox it looked like it was just looping and looping forever.. a solid 5 minutes at least before I force-quit it cause Firefox was bogged down so badly I couldn't do anything. The scroll bar on the side just kept getting smaller and smaller.

In IE it just hung... I had to End Task to get it to stop.

Again, this was using the original code you posted at the beginning of the thread. With the updated code for 1.4.8 nothing happens at all, just a script error.

--

So, I tried it again and let it sit for ten minutes. One core on the processor is working hard bouncing between 85-95%, but again, it doesn't finish. I attached a screenshot (for what it's worth). If I try to do anything in firefox while it's running the script FF is really sluggish to respond (3-5 seconds) but it did let me close the tab when I finally stopped it.

--

I'm assuming the way it's supposed to work is, it adds them all in, then the list collapses back down when it's done with "all zones" set to each country? Maybe it's just my computer.. who knows?

Attachments

ScreenHunter_01-Sep.-13-16.00.jpg

ScreenHunter_01-Sep.-13-16.00.jpg (64.35 KiB) Viewed 8886 times


Newbie

Posts

Joined
Sat Dec 05, 2009 4:59 am

Post by Qphoria » Tue Sep 14, 2010 4:12 am

the zones field shouldn't get that big

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 PaulineNMU » Tue Sep 14, 2010 4:19 am

Lol.. no, I didn't think so.. But I'm not sure why it's doing that. I'm afraid my javascript skills are weak.

Here's what I have, maybe I made a mistake:

Line 62:

Code: Select all

            <td class="left"><a onclick="addGeoZone();" class="button"><span><?php echo $button_add_geo_zone; ?></span></a><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></td>
Line 104 (the end):

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>
The add button code didn't match up perfectly, but it didn't seem to me that the SPANs should matter much, they just make the button aligned weird. But maybe that's breaking it?

I appreciate the help! :)

Newbie

Posts

Joined
Sat Dec 05, 2009 4:59 am

Post by IBBoard » Sat Sep 18, 2010 3:50 am

Wow, that's a horrendous amount of AJAX requests. I just added this to my wife's shop and even on a Core i5 with 4GB RAM in Chromium (supposedly one of the faster JS browsers) it hammers a processor for minutes or more. I tried stripping out the loop to generate the lists and swapped to a hidden field and text for the country name, but it looks like the crippling delay is in its AJAX requests to populate the zones for each country.

Other than assuming "all zones" and hard-coding that as well then I'm not sure there is much that you can do. Even then, that'll only work the first time that you click the button. After that then if you ever accidentally edit the "Rest of World" zone then you're still going to be hit by the 200+ AJAX requests and the old grinding slowness.

I knew there was a reason that I thought this reliance on Ajax was bad :\ Thank goodness for Chromium keeping tabs in separate processes so that the entire browser doesn't die!




[Edit]
Okay, to be a bit more constructive, here is my hackish version. Your browser is still toast the second you go to edit the group, but that's unavoidable because of the architecture of OpenCart. You have been warned! As it is I appear to be safe, because PHP hits its 64MB memory limit first :choke:

The only limitation of this implementation is that it assumes "All Zones" for all nations, but given the purpose then hopefully it'll work for most people :)

Find:

Code: Select all

<a onclick="addGeoZone();" class="button"><span><?php echo $button_utton_add_geo_zone; ?></span></a>
After, add:

Code: Select all

<a onclick="addAllGeoZones();" class="button"><span>Add All Countries</span></a>
(This fixes the button styling)

Find:

Code: Select all

function addGeoZone() {
Before, add:

Code: Select all

function addAllGeoZones() {
<?php foreach ($countries as $k => $v) { ?>
    html  = '<tbody id="zone_to_geo_zone_row' + zone_to_geo_zone_row + '">';
    html += '<tr>';
    html += '<td><?php echo $entry_country; ?><br /><input type="hidden" name="zone_to_geo_zone[' + zone_to_geo_zone_row + '][country_id]" id="country' + zone_to_geo_zone_row + '" value="<?php echo $v['country_id']; ?>" /><?php echo addslashes($v['name']); ?></td>';
    html += '<td><?php echo $entry_zone; ?><br /><input type="hidden" name="zone_to_geo_zone[' + zone_to_geo_zone_row + '][zone_id]" id="zone' + zone_to_geo_zone_row + '" value="0"/>All Zones</td>';
    html += '<td rowspan="2"><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').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 } ?>
}
Hopefully that helps some people, it's just a shame that the OpenCart architecture can't handle it. Maybe we need negative GeoZones to say "all countries except X, Y and Z" :D
Last edited by IBBoard on Sat Sep 18, 2010 4:01 am, edited 1 time in total.

New member

Posts

Joined
Sun Sep 12, 2010 3:30 am

Post by Qphoria » Sat Sep 18, 2010 4:00 am

yea.. it was just a hacky bandaid that obviously shows the need for a proper fix. I will make this a priority to work on

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 IBBoard » Sat Sep 18, 2010 9:31 pm

It requires more work, but what I thought about last night after my post was that you could stick with the AJAX but only use it when necessary. Basically, if you make everything show a string on edit and mass add, with the drop-down for a single add or when you click on an "Edit" link then you'd get the AJAX functionality and still be quick and not memory hungry. Hopefully that makes sense :)

New member

Posts

Joined
Sun Sep 12, 2010 3:30 am

Post by sourcez » Sun Nov 07, 2010 11:31 pm

Thanks for this, found it extremely useful. I ran the updated code in Chrome and just let it get on with it.

With the zones I used a text box instead so you have some choice on setup and don't have to load the page again.

Another upside of having done this is I can now take zone data directly from the database and copy it to other shops.

Newbie

Posts

Joined
Sun Nov 07, 2010 11:28 pm

Post by deeve » Fri Nov 26, 2010 1:19 am

Was thinking the other day whilst creating yet more Geo Zones for a client, wouldn't it be great to have pre-bundled Territories such as: EEC, ROW & any other major grouped Zones [dependent upon your Country & the other Zones you already have declared].

I know it's easy to suggest such tweaks & another thing to write them but just thought it worth a mention in the hope it may be possible one day.

Active Member

Posts

Joined
Tue Oct 20, 2009 4:31 pm

Post by addaiamark » Sun Nov 28, 2010 10:07 pm

I have the opposite problem I think? I need to take orders from multiple countries, but all deliveries are in 1 area. how do I make the shipping address default only to that area, and not a whole drop down of countries I don't need? ???

Newbie

Posts

Joined
Mon Nov 22, 2010 12:56 am

Post by tonnaer » Mon Jan 17, 2011 4:05 am

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:

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>
This takes away the possibility of choosing countries and zones in favor of speed, so you'll have to save and re-enter to be able to change the zones if you want to.

By the way, when I re-enter the geozone edit page, it seems like the page is constructed again using js, because very slowly all countries and their zone select boxes are added to the page. Really that should be handled all in PHP in one go. Now it takes ages, and quite some countries are getting empty zone select boxes, even when they should have zones to choose from.

Newbie

Posts

Joined
Mon Jan 17, 2011 3:58 am

Post by glolar » Mon Feb 07, 2011 12:50 pm

Has this ever been resolved? I desperately need to be able to create a "World GeoZone" that contains all countries, so I can set up my shipping (V 1.4.9.3).

Thanks in advance.

Increase Your Child's I.Q.
iPad Wallpapers
Turtle & Tortoise Screen Savers


User avatar
Active Member

Posts

Joined
Thu Jul 29, 2010 12:35 pm
Location - San Diego, CA

Post by ambrosite » Fri Mar 18, 2011 11:21 am

I am really surprised that people are trying to do this with JavaScript? That's crazy. You can set up an "All Countries" Geo Zone in a half second by running a SQL query directly against the database.

First of all, setup the Geo Zone in the admin as you normally would, but don't add any countries or zones to it. Next, you need to know the geo_zone_id of the Geo Zone you just created. You can find it at the end of the URL when you edit the Geo Zone:

http: //www.mystore/admin/index.php?route=local ... _zone_id=4

Now, run the following SQL query using a tool like phpMyAdmin. Make sure you edit the query with the table prefix you selected during the OpenCart installation ('oc_' for my database). You need to enter the correct geo_zone_id in the third field on the second line (it was '4' in my case):

Code: Select all

INSERT INTO oc_zone_to_geo_zone (country_id, zone_id, geo_zone_id, date_added, date_modified)
SELECT oc_country.country_id, 0, 4, NOW(), NOW()
FROM oc_country
WHERE oc_country.name NOT IN ('United States');
That's it! The query will complete in less than two seconds, and it will add all countries and all zones except the United States to your Geo Zone. Note that you can easily edit the query to exclude more than one country. For example, if you wanted to create a Geo Zone for all countries except the US and Canada, you would do this:

Code: Select all

INSERT INTO oc_zone_to_geo_zone (country_id, zone_id, geo_zone_id, date_added, date_modified)
SELECT oc_country.country_id, 0, 4, NOW(), NOW()
FROM oc_country
WHERE oc_country.name NOT IN ('United States','Canada');

Newbie

Posts

Joined
Sat Jan 08, 2011 5:15 am

Post by Qphoria » Fri Mar 18, 2011 12:15 pm

not everyone knows how to use mysql.. people know how to click a button. Granted this should be done with ajax now .. but this is also over a year old.. it hasn't worked for a while

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 ambrosite » Fri Mar 18, 2011 12:22 pm

Qphoria wrote:not everyone knows how to use mysql.. people know how to click a button. Granted this should be done with ajax now .. but this is also over a year old.. it hasn't worked for a while
True, but in order to even add the button they have to know how to edit the templates, so obviously some level of technical knowledge is assumed.

Anyway, I had to solve this problem for one of my clients so I thought I'd share it here, in case it might be useful to someone.

Newbie

Posts

Joined
Sat Jan 08, 2011 5:15 am

Post by Seuldieu » Sat Mar 19, 2011 6:48 pm

Just in time for my project. +1 ambrosite!

New member

Posts

Joined
Fri Dec 10, 2010 7:21 am

Post by glolar » Mon Mar 21, 2011 9:22 am

Thanks, ambrosite,

I also knew that this could be accomplished with a sql call, but my sql skills are rusty, and I did not want to muck it up, so I spent about 15-20 minutes adding the countries manually.

On my next OC installation, I will be sure to use your code.

Thanks again.

Increase Your Child's I.Q.
iPad Wallpapers
Turtle & Tortoise Screen Savers


User avatar
Active Member

Posts

Joined
Thu Jul 29, 2010 12:35 pm
Location - San Diego, CA

Post by webpie it. » Fri May 06, 2011 3:18 pm

The above suggestions on page 2, worked for me perfect, I am running about a 3 year old imac and added them in less than 10 seconds. Used "tonnaer" script fix.

Running V 1.4.9.4
V 1.4.9.3
Worked on Both on my system, thanks guys, adding the world would have been a nightmare if i hadn't found this!

Many regards

Regards

Chris


Active Member

Posts

Joined
Mon Jan 31, 2011 7:28 pm

Post by xtr3mx7 » Thu Jun 02, 2011 11:56 pm

Indeed the solution suggested by IBBoard works perfectly fine though it takes a little bit of time to complete.

New member

Posts

Joined
Mon Jul 13, 2009 1:02 am

Post by Brad » Sat Jun 18, 2011 10:49 pm

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!

Newbie

Posts

Joined
Wed Mar 23, 2011 4:48 am
Who is online

Users browsing this forum: No registered users and 9 guests