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?
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 (64.35 KiB) Viewed 12960 times
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:
Line 104 (the end):
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!
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>
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>
I appreciate the help!
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
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:
After, add:
(This fixes the button styling)
Find:
Before, add:
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"
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
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>
Code: Select all
<a onclick="addAllGeoZones();" class="button"><span>Add All Countries</span></a>
Find:
Code: Select all
function addGeoZone() {
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 } ?>
}
Last edited by IBBoard on Sat Sep 18, 2010 4:01 am, edited 1 time in total.
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
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.
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.
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.
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.
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?
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:
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.
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>
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.
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.
Thanks in advance.
Increase Your Child's I.Q.
iPad Wallpapers
Turtle & Tortoise Screen Savers
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):
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:
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');
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');
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.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
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.
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.
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
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
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
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
2. Then take this number (this example uses 6) and replace the number 6 in the following SQL
Done!
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'
Code: Select all
INSERT into zone_to_geo_zone (country_id, geo_zone_id)
SELECT country_id, 6
FROM country
Who is online
Users browsing this forum: No registered users and 74 guests