2 replies [Last post]
asimon's picture
Offline
Joined: 12/08/2011
Juice: 21
Was this information Helpful?

Hi, I need to run some code each time a user submits an order. I'm using Drupal 7 w/ UC 3 and I'm not entirely sure what the appropriate hook is to use for this (or if there even is one?)

It's an export script, so additionally, I'm curious if I'll run into any problems if my code tries to query this order by:
db_query("SELECT primary_email FROM {uc_orders} ORDER BY order_id DESC LIMIT 1")->fetchField();
in other words, when is an order_id created? is it done when the user submits their order or some time before that?

If there's going to be a problem with that, can I run a series of hooks so i can store the order_id as a variable as soon as it's created, and if it goes to completion, that variable gets passed to the rest of the code?

asimon's picture
Offline
Joined: 12/08/2011
Juice: 21
Re: Order submitted hook?

OK, found uc_checkout_complete($order, $account), and confirmed I may run into some problems using my lookup last record technique.
So I'm trying to take advantage of the $order argument and ran into some problems.

$oid = $order[0];

Is giving me an error:
Fatal error: Cannot use object of type stdClass as array in .../file.module on line 5

Any idea why?

dooffas's picture
Offline
Joined: 01/20/2012
Juice: 46
asimon wrote: $oid =
asimon wrote:
$oid = $order[0];

Is giving me an error:
Fatal error: Cannot use object of type stdClass as array in .../file.module on line 5

This is a standard php error. This is usually because you are trying to access or use an object like an array.

$order is probably an object rather than an array.

Can you:
echo var_dump($order)

This will output the contents of the object in a structured way and you will be able to see if $order is an object or an array.
If it does turn out to be an object you can access it like:
$oid = $order-> objectNameHere