Not working

Project:Ubercart Location integration
Component:Code
Category:
Priority:critical
Assigned:Unassigned
Status:active
Description
Project: 
uc_location

Hi, I was looking exactly for this module, and wanted to hire an external developer to do this. I'm thinking to assign them to help you on this module.

I installed your module on Ubercart 2.0-rc7.
Unfortunately I can't see any changes on the user account pages...

During the checkout process, I get this errors:

checkout page:

warning: Invalid argument supplied for foreach() in
/sites/all/modules/ubercart/contrib/uc_location/uc_location.module on line 111.

review page:

warning: Invalid argument supplied for foreach() in
/sites/all/modules/ubercart/contrib/uc_location/uc_location.module on line 111.

In the readme.txt the links are not working. Ex: http://drupal.org/project/uc_location

Thanks!

Version: 
Ubercart 2.0-RC1
mearnest's picture
Offline
Joined: 09/28/2009
Juice: 34
Re: not working

A check has been added to make sure the user locations is set before the foreach call on what used to be line 111. If it isn't set, an empty array is returned for the drop down address selection field. This module's dependency includes location and user_location, but if those modules were installed after existing users, then those older users may not initially have a user locations array.

The links to the drupal project are now working.

yanku's picture
Offline
Joined: 08/25/2009
Juice: 55
Re: Re: not working
Assigned to:mearnest» yanku

mabe the error has also to do with the ubercart rc7 I was using.
longwave will prepare a compatibility-upgrade for rc7 and upload a patch.
Maybe it is solved then.

Anyway, I think there should be no error. As there might be cases, where this module (and user_location etc.) is installed on a running site, which already has users, we should think about a solution.

Let´s say the check is done at checkout.
In case there is a user with no locations arrays yet, then the module should create an empty one, on the fly.
Or there should be a database update during the module installation, that creates the fields for each user, who don‘t have them yet.

(by create "an empty locations array" I mean, to prepare the user tables with the needed fields, that it at least look like the user has no saved addresses yet – no errors)

mearnest's picture
Offline
Joined: 09/28/2009
Juice: 34
Re: Re: Re: not working
Assigned to:yanku» mearnest

Hopefully the rc7 patch will solve it. If not, I'll get back to you on handling missing locations without issuing an error.

You had initially mentioned that no changes appeared on the user account. That's because we were at first only using the location fields provided. There is now a module (location_first_last_org) for adding a first name, last name and organization field for each user location. I've uploaded it to Ubercart and linked to it from here. We will release it as a drupal project in a few days. If this module is installed, the latest uc_location revision will make use of those fields.

Also, uc_location does set a primary (default) location. There is another module (user_primary_location) I've also uploaded here where the user (or administrator) can set a primary location on the user profile. But uc_location and user_primary_location have no direct relationship. We had need to set a primary location for our salesforce - ubercart integration.

bibeksahu's picture
Offline
Joined: 06/09/2009
Juice: 75
Re: Re: not working
Assigned to:mearnest» bibeksahu

It appears (and the code in the "location_user" module suggests) that the "$user->locations" and "$user->location" arrays always get set for a user, as long as the module "location_user" is activated.

If the user does not have any locations, then it returns empty arrays.

from "location_user.module", line 40:

/**
* Implementation of hook_user().
*/
function location_user_user($op, &$edit, &$account, $category = NULL) {
  global $user;

  switch ($op) {
    case 'load':
      $account->locations = location_load_locations($account->uid, 'uid');
      $account->location = count($account->locations) ? $account->locations[0] : array();
      break;

There should not be any errors in using the arrays, as long as you account for the fact that the arrays may be empty.

The mistake we made in our first release here was that we had the "location" module as a dependency, but not "location_user". The code above comes specifically from "location_user". If a person has "location" installed and active, but not "location_user", then the arrays may not be set - this is what KiamLaLuno was getting at, in his comments to our cvs application at drupal.org.

We have addressed this by making "location_user" a dependency of "uc_location". It should have been the case from the beginning, since this module works solely with user locations.

Thank you for the -rc7 assistance. It is on our TODO list, but is a slightly lower priority to getting the site running quickly with the versions of everything that we're already using.

bibeksahu's picture
Offline
Joined: 06/09/2009
Juice: 75
Re: Re: not working

Hi,

We're now seeing the error you mention. We don't know why. We're working on it, and will get back to you soon on this.

- Bibek

bibeksahu's picture
Offline
Joined: 06/09/2009
Juice: 75
Found it!

It turns out that the Organic Groups module had essentially this same problem: http://drupal.org/node/285696

From og.module, line 277:

    global $user;
    // Adventurous modules can cause us to arrive here before og_init() has fired.
    // See ">http://drupal.org/node/285696
    if (!isset($user->og_groups)) {
      $user = user_load(array('uid' => $user->uid)); 
    }

We fixed the problem by implementing essentially the same solution, just checking "$user->location" instead of "$user->og_groups". We didn't see the problem on our test setup because we have Organic Groups active there - and since og gets called before uc_location, the code fragment above was fixing our problem. As soon as we moved it to our final destination, which did not have OG active, it broke. We have fixed the problem on our setup, and will have the fix in CVS soon (probably tomorrow or Saturday).

- Bibek

yanku's picture
Offline
Joined: 08/25/2009
Juice: 55
Thanks! Please see also the
Assigned to:bibeksahu» yanku

Thanks!

Please see also the Ubercart rc7 compatibility patch, posted by longwave:
http://drupal.org/node/600006

I tested it briefly and it seems to work out fine.

bibeksahu's picture
Offline
Joined: 06/09/2009
Juice: 75
Grazi!
Assigned to:yanku» bibeksahu

Thank you!

We'll get it reviewed and applied as soon as we can (we're a bit buried at the moment). For now I've updated the project page to point to the patch, so others can easily find it.