1

I have seen similar questions such as drupal :: order complete hook and upgrade user permission/roles which would work for me except that my order never reaches completed, only payment_received. At this time the uid is 0. It still doesn't work if I add a conditional action under "Customer completes checkout" to mark the status as complete as the uid is still 0.

So my question is, how can I get the uid and the order object after the user has successfully completed checkout and been created?

Community
  • 1
  • 1
Mark Aroni
  • 605
  • 1
  • 10
  • 21

1 Answers1

0

When Ubercart creates the user it also logs them in so you would just have to do this to get the uid:

global $user;
$uid = $user->uid;

It would probably be best served in hook_order() as mentioned in the similar question you linked to.

UPDATE

If there's no uid associated with the order you should be able to something like this:

function MYMODULE_order($op, &$order, $arg2) {
  if ($op == 'update' && $arg2 == 'payment_received') {
    if ($order->uid) {
      $uid = $order->uid;
    }
    else {
      global $user;
      $uid = $user->uid;
    }
  }
}
Clive
  • 36,918
  • 8
  • 87
  • 113
  • Thanks, I thought about using the email address of the order to look up the uid, but of course the user isn't created at this time and a hook needs to be exposed later on. I guess I could use hook_user with the insert operation to check to see if the email address has any orders that are uid 0 and created within a certain time limit? This seems messy to me, is there not a better solution? – Mark Aroni Sep 12 '11 at 22:35
  • Sorry I meant in `hook_order()` not `hook_user()`. Are you sure this isn't an anonymous checkout scenario? If it is the `uid` will always be zero as no user's ever created. If not, by the time your `hook_order()` is called with the 'update' argument the user should definitely be created and the order should be populated. If it isn't, using `global $user` will get you the currently logged in user and you should be able to get the `uid` that way – Clive Sep 12 '11 at 23:31
  • Thanks Clive, that makes sense, although from what I have previously tested, it seems your code above would always use the global $user, I had it setup to send emails for every scenario with the contents of the arguments. We have the settings so that the user is created on successful order, this does happen, just too late. From what I can see from your code however, even the global $user will be 0 at this time as they're not logged in nor created. – Mark Aroni Sep 13 '11 at 10:08