Hook_Order() Help Needed

Posts: 95
Joined: 10/29/2007
Bug Finder

I have an existing shipping / inventory control system that I wrote in vb.net a year agao, and it works great for shipping our daily orders. It interfaces with scales, OCR scanners, etc. It's got a MYSQL backend, so interfaceing it will be easy. I need to do the following. When a user completes an order, I need to write all the order info over into my system.

I've written a Paypal IPN interface which works great when we get a Paypal order from Ebay, etc. so I have written all the queries I'll need, but I have some questions on how to interface this with Ubercart.

I'm assuiming I'll use hook_order() and do a mymodule_order() function to save the data. Here are my questions.

1. What order state do I want to look for. I need to make sure this is called only 1 time after an order has been submitted and payment has been approved. Do I use 'submit', 'save', or is there a status that 'complete'?

2. I'm assuming I can read all the data I need from teh Order object, Where is the order object documented, I can't find a place that list all the variables that I'll need to read to get email, address, product details, etc. This must be somehwere, but I could not find it.

3. Does someone have an example of a hook_order module that writes data to a 3rd party system, I didn't see one, but if we don't have one on the forum, I can post my code up once it's complete tomorrow as an example.

I want to code this later today, so if you have any ideas or shortcuts I should use to build the interface, please share.

Jim

Posts: 2244
Joined: 08/07/2007
AdministratoreLiTe!

Since other modules can hook in and change the $order object without us really knowing about it, documentation would only be so useful. Fortunately, there's print_r().

<?php
  drupal_set_message
('<pre>'. print_r($order, true) .'</pre>');
?>

This snippet will display the $order object in all its structured glory.

Posts: 5269
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Also, you'll need to use a different $op depending on when you want to act on these orders. If you only want to do it when they're moved to a completed status, then I'd use 'update' and check to see if the new status is part of the completed state (uc_order_status_data($status, 'state');). If you just want to do it post checkout (like if you're charging cards at checkout through the site), you can use the 'submit' $op. You might want to check to make sure the balance is $0 for this to go through. Also, if I were you, I'd keep a second table running of all the orders you've exported so you don't do it twice on accident.

Posts: 95
Joined: 10/29/2007
Bug Finder

Do they go to the completed state after a successful charge during checkout, or does this happen after an admin changes the state of an order to complete - ie after they fulfill.

Posts: 95
Joined: 10/29/2007
Bug Finder

Lyle,
Thanks for the tip on the print_r, I use it all the time and was going to do that, but it's not a bad idea to document the main object and status codes. I usually like to plan my strategy for coding before I start laying code. This usually means I look at documentation to see if I have all the hooks, events, and variables I need. I searched hook_order on the site an forum first last night to find out how to do this, but since there was no docs or example on it, I had to post a question.
But you're right in the fact, that all the other modules will be modifying it, so it will look different based on when I use it.
Thanks for all your help.
Jim

Posts: 5269
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Orders don't go to the completed state by themselves. Orders default to the pending state after checkout, but some modules (like PayPal) may have code that moves them to "Payment received." You can use Workflow-ng in the latest version (from Bazaar, soon to be released as Alpha 8 ) to update the status to whatever you want at checkout.