I post a lot of dumb questions, but I'm trying to figure this out for myself.
First, in the Gateway Complete template, there are several Smarty variables that give access to the important information:
$ordernumber = the Orders module order number
$email_address = buyer's email address
$status = SUCCESS if order was successful
$gateway_success = the actual success code from the Gateway, in the case of Paypal success = "payment_approved"
$transaction_id = the Gateway's transaction ID
$tmp = a number that appears to be the transaction amount. Not sure if this is intended to be used.
There are also array/objects:
$item = Array(12) ? I have not gotten this to print_r as anything but 1, maybe I'm doing it wrong.
$shipping = Array(22)
********************************************************
Ok, so I want to write a UDT that takes the order number and does something with it. It appears there are two different ways I could do this:
1. Put a UDT in the Gateway Complete Template of the Orders module. With this I could use the $ordernumber to look up a transaction in the Orders database and then do something with it.
OR
2. Orders Module registers an event "PostGatewayComplete". We can write a UDT and use Event Manager to call it when PostGatewayComplete is fired. Question: what data is captured or passed in this event?
Looking in the Orders Code, you can find the relevant piece of info:
At the very end of action.gateway_complete.php you find the DoEvent call:
Code: Select all
// Send Event w/ Order information
Events::SendEvent('Orders', 'PostGatewayComplete', array('order_id' => $order_id, 'order' => $order));
So from this I see that two parameters are passed in the $params array: 'order_id' and 'order'
So now I can write a UDT that takes that info and does something.
Code: Select all
global $gCms;
$ordernumber = $params['order_id'];
$order = $params['order'];
code to do something....
I want to know more about the "order" object that is being passed here, so I can retrieve the item id's and quantities. So search around in the Orders module code some more I notice that $orders, $order, and $item are arrays of key=>value pairs, not objects as I had thought. So I was using the object->notation and that is why I was failing to get the values printed from item.
Here is the structure of the orders array in a way that is easy to read:
Code: Select all
Array (
[0] => Array (
[id] => 3
[order_id] => 2
[shipping_first_name] => Joe
[shipping_last_name] => Smith
[shipping_address1] => 3610 River Road
[shipping_address2] =>
[shipping_city] => Mendota
[shipping_state] => VA
[shipping_postal] => 24270
[shipping_country] => US
[shipping_phone] => 2766693455
[shipping_fax] =>
[shipping_email] => joeSmith@gmail.com
[shipping_message] =>
[subtotal] => 0.02
[tax] => 0
[shipping_cost] => 0
[total] => 0.02
[weight] => 0
[create_date] => 2009-08-04 07:16:24
[modified_date] => 2009-08-04 07:16:24
[items] => Array (
[0] => Array (
[id] => 3
[order_id] => 2
[shipping_id] => 3
[item_id] => 1
[quantity] => 2
[product_name] => Test Payment
[details] =>
[price] => 0.01
[weight] => 0
[status] => notshipped
[create_date] => 2009-08-04 07:16:24
[modified_date] => 2009-08-04 07:16:24
)
)
)
)
Likewise, here is the $item array in the same format:
Code: Select all
Array (
[id] => 3
[order_id] => 2
[shipping_id] => 3
[item_id] => 1
[quantity] => 2
[product_name] => Test Payment
[details] =>
[price] => 0.01
[weight] => 0
[status] => notshipped
[create_date] => 2009-08-04 07:16:24
[modified_date] => 2009-08-04 07:16:24
)
This information is available in the Gateway Complete Template as well as passed by the PostGatewayComplete event.
I hope this will be helpful to other intermediate beginners like me.
Have a nice day.