In Ubercart, selecting a country (for example Aruba) without a zone results in the zone field being filled in with 'not applicable'.

In the address module, if a country is selected that doesn't have a zone, the address module runs and runs, trying to find the zone list.

I'd like to put a 'critical' priority on this because it is personally critical, but the reality is that it is probably 'normal' ;)

Thanks,

Conrad

Comments

freixas’s picture

Assigned: Unassigned » freixas
Priority: Normal » Critical
Status: Active » Postponed (maintainer needs more info)

There are several places where a user can enter an address, but in the code they all boil down to two: it's either during checkout (when all the entry is handled by Ubercart code) or it's during registration or profile editing, when it goes through uc_addresses_address_pane.inc.

Could you verify which case(s) you have a problem with?

Do you know for certain that the module runs and runs trying to find the zone list or is this just a guess (for example, the browser could be waiting for a response to an AJAX request which is not arriving and maybe no one is actually looking for the zone at all)? If this is not a guess, let me know what debug information you may have acquired.

Are you a programmer able to trace through the code? I could point to some places to look at.

Finally, to make you happy, I changed the priority to 'critical'. It's still just me at this end trying to fix all bugs as best I can. :-)

Sdarnoc’s picture

Hi freixas,

I'm looking at it a little closer. Here's what's happening:

/cart/checkout = United States & all US states can be selected. All countries show in pull-down. All countries can have their states/provinces selected.
/user/1/addresses/1/edit = works fine, as above.

But...

/user/register = United States & all US states can be selected. All countries show in country pull-down, but when any other country is selected, the busy icon goes round 'n round. The "states/provinces" menu never gets populated.

I turned on the dev module for help, and then addresses didn't want to work anywhere. So I turned it off.
The admin complained that it wanted to run the update database script, so I did that.

OK, so what do I do or install to help trace?

freixas’s picture

Actually, you gave me some good info.

Before we go further, make sure you have the latest 5.x-2.x-dev release installed and have run update.php.

Now let's check on what fails: checkout changes should be OK. Does 'edit' still work? Does 'register' ('new') still hang? How about 'add'?

At this point, I hope you tell me everything is working great. I have an installation with only US and Canada installed. When I select Canada during registration, the zone field gets updated to show the Canadian provinces.

If you're a PHP programmer, this will go a lot faster. Look at uc_addresses_address_pane.inc. The first method, uc_addresses_pane_address, has two options for handling addresses. One is for 'new' and 'add' (this is the case that fails for you) and the other is for 'edit'.

The relevant 'edit' code looks like this:

if (uc_address_field_enabled('zone')) {
  if (isset($_POST['panes'], $_POST['panes']['address'], $_POST['panes']['address']['country'])) {
    $country_id = intval($_POST['panes']['address']['country']);
  }
  else {
    $country_id = $arg1->country;
  }
  $form['address']['zone'] = uc_zone_select(uc_get_field_name('zone'), $arg1->zone, NULL, $country_id, 'name', uc_address_field_required('zone'));
}

The 'new' and 'add' code looks like this:

if (uc_address_field_enabled('zone')) {
  $country_id = $arg1->country;
  if ($op == 'add') {
    if (isset($_POST['panes'], $_POST['panes']['address'], $_POST['panes']['address']['country'])) {
      $country_id = intval($_POST['panes']['address']['country']);
    }
  }
  else {
    if (isset($_POST['country'])) {
      $country_id = intval($_POST['country']);
    }
  }

  $form['address']['zone'] = uc_zone_select(uc_get_field_name('zone'), $arg1->zone, NULL, $country_id, 'name', uc_address_field_required('zone'));
}

The code here actually splits to handle 'add' and 'new' separately. The logic is the same, the location of the country info is different. The obvious thing to check is the value of $country_id just before calling uc_zone_select(). You want to see what the value is in the cases where the code works and what the value is in the cases where the code fails.

If the values are different, then look at $arg1 and $_POST to see if the right value is available. If the values are the same, then maybe the problem is outside of the uc_addresses module.

Let's see how far this gets you.

Sdarnoc’s picture

OK,

Uninstalled, and then installed -dev
Ran update.php -- no errors

Added echoes above the uc_zone_selects for:
line number
$country_id
$arg1
$_POST

------------------

/cart/checkout

1) No echoes when selecting different countries.
2) If address is 'default' in profile -> everything works
3) If default country is changed to country B -> Error msg: An illegal choice has been detected. Please contact the site administrator.
4) If back button is used and country B is changed to country C and then click forward -> everything works

------------------

/user/1/addresses/3/edit

1) Arrive at page and get echoes:
about line 152
country_id = 32
arg1 =
_POST = Array ( )

and error msg: recoverable fatal error: Object of class stdClass could not be converted to string in /home/imnweb/public_html/sites/all/modules/uc_addresses/uc_addresses_address_pane.inc on line 158.

2) Change country and state, the hit 'update' and get echoes:
about line 152
country_id = 124
arg1 =
_POST = Array ( [panes] => Array ( [address] => Array ( [first_name] => aoeu [last_name] => eud [phone] => [company] => kxm [street1] => uh [street2] => pfg [city] => oeui [country] => 124 [zone] => 1369 [postal_code] => qjkx [address_name] => [aid] => 3 ) ) [op] => Update address [form_token] => bd514632355ce16e7248b463a8d49b00 [form_id] => uc_addresses_get_address_form )

Page that is supposed to show updated address is white, no text or images

------------------

/user/register

1) Arrive at page and get echoes:
about line 78
country_id =
arg1 =
_POST = Array ( )
2) Try to change country, and it hangs

freixas’s picture

Well, we gained some information, but not as much as you might think.

/cart/checkout

1) No echoes when selecting different countries.
2) If address is 'default' in profile -> everything works
3) If default country is changed to country B -> Error msg: An illegal choice has been detected. Please contact the site administrator.
4) If back button is used and country B is changed to country C and then click forward -> everything works

The error in 3) means that the zone doesn't match the country. I believe the error comes from the ubercart code, not uc_addresses. uc_addresses just takes the country/zone that ubercart gives it and stores them without further checks.

Are you sure you have the latest ubercart code installed? If you install the "Update Status" module, it will give you an easy way to check for outdated modules.

and error msg: recoverable fatal error: Object of class stdClass could not be converted to string in /home/imnweb/public_html/sites/all/modules/uc_addresses/uc_addresses_address_pane.inc on line 158.

I suspect the error is in your debug statements and that you used echo $arg1 instead of print_r($arg1) or var_dump($arg1).

The line numbers in your code won't match mine because of the added debugging statements. You will need to send me a copy of the line with the error (and the surrounding content).

Page that is supposed to show updated address is white, no text or images

Not sure about this. It may be a side-effect of printing out the debug statements. Here's what I use:

file_put_contents("filename", "country_id = $country_id, arg1 = " . print_r($arg1, true) . "\n", FILE_APPEND);

where "filename" is replaced by whatever file you want the debug messages to go to. This won't interfere with the Web site display. Note the use of print_r() with "true" as the second value to get the object data into the string.

2) Try to change country, and it hangs

When you try to change the country, an AJAX message is sent to the server. Debug statements will screw up the response, so at this point, we don't know what happened on the receiving end. Try using the file_put_contents() approach to recording debug to a file.

The problems you are reporting are pretty serious. I am not able to reproduce them and I am not having an army of people chasing me to get this fixed, so I'm guessing there's something specific about your installation that's the source of the problem. This will be difficult for me to debug remotely. The more debug work you can do, the faster it may go. The code handling the country/zone has been a big headache for me. It's part of Ubercart and I don't know exactly how it works.

Sdarnoc’s picture

Hi freixas,

Drupal 5.14
/admin/logs/status = all green
/admin/logs/updates = all green
Addresses 5.x-2.x-dev
Cart 5.x-1.6

---------------

Checkpoint 1 (approx line 78)

          if (isset($_POST['country'])) {
            $country_id = intval($_POST['country']);
          }
        }

file_put_contents("address_debug", "Checkpoint 1:\npage = " . $_SERVER['REQUEST_URI'] . "\ncountry_id = $country_id\narg1 = " . print_r($arg1, true) . "\n_POST = " . print_r($_POST, true) . "\n", FILE_APPEND);

        $form['address']['zone'] = uc_zone_select(uc_get_field_name('zone'), $arg1->zone, NULL, $country_id, 'name', uc_address_field_required('zone'));
      }

Checkpoint 2 (approx line 151)

        else {
          $country_id = $arg1->country;
        }

file_put_contents("address_debug", "Checkpoint 2:\npage = " . $_SERVER['REQUEST_URI'] . "\ncountry_id = $country_id\narg1 = " . print_r($arg1, true) . "\n_POST = " . print_r($_POST, true) . "\n", FILE_APPEND);

        $form['address']['zone'] = uc_zone_select(uc_get_field_name('zone'), $arg1->zone, NULL, $country_id, 'name', uc_address_field_required('zone'));
      }

---------------

First stop: /user/register

Try to change country & state -- address hangs

/admin/logs/watchdog error = access denied 12/22/2008 - 06:55 uc_js_util/zone_select

Hmm. Looks like it may be that the registration code module is denying access...
No. I turned it off, and the problem is still there.

find . -type d -name uc_js_util -> no directory found
OK, so it's missing. Tried untarring ubercart again, couldn't find it there. Why is it missing? Where do I get it?

address_debug file entry:

Checkpoint 1:
page = /user/register
country_id =
arg1 =
_POST = Array
(
)

---------------

Second stop: /cart/checkout

Try to change country & state from default --
/cart/checkout error = An illegal choice has been detected. Please contact the site administrator.
/admin/logs/watchdog error = form 12/22/2008 - 07:04 Illegal choice 1308 in State/Province ...

But nothing put into the address_debug file.

---------------

Last stop: /user/1/addresses/4/edit

Change the country & state -> All works properly

address_debug file entry:

Checkpoint 2:
page = /user/1/addresses/12/edit
country_id = 124
arg1 = stdClass Object
(
[aid] => 12
[uid] => 1
[first_name] => Jose
[last_name] => Argent
[phone] =>
[company] =>
[street1] => argent street
[street2] =>
and so on...

Conrad

freixas’s picture

First stop:

You used 'find'. Don't forget to try 'grep' as well.

uc_js_util is a Drupal path. uc_country_select.js contains Javascript which makes an AJAX call to the uc_js_util/zone_select path. In uc_store.module, there is a method that handles this path. You must have 'access content' permission to use this method.

I suspect that there is no hang—the code is waiting for a response, but it does so asynchronously, so you should be able to fill in remaining fields, press "Submit", etc. The address won't have a valid country/zone, though.

Second stop:

I still believe that this is an ubercart bug, not a uc_addresses bug. One way to find out: disable uc_addresses and try placing a checkout order.

You won't capture anything with your debug statements because the order system is handling the address, not uc_addresses_address_pane.inc. I use a hook to get the address the order system acquired. The hook is in uc_addresses.module.

If the bug remains after disabling uc_addresses, you need to file a problem report with Ubercart.

Third stop:

Interesting. Edit works? Maybe it's because you have to be logged in and now have 'access content' permission.

I'll think about this, but in the meantime there are two things you can try:

  1. Give anonymous uses 'access content' permission and see if this improves the registration process.
  2. Try disabling uc_addresses and see if you still have a checkout address problem.
freixas’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Closed due to lack of response.