Re: Sending order data to a script
You're probably right about thinking you need to check the server's logs. But I'm guessing it's your server's mod_sec logs you need, and that you've probably tripped a rule that's intended to block hackers because something you're passing is very similar.
The script you're posting TO isn't running any Zen Cart code, is it?
Re: Sending order data to a script
It turned out to be a PHP error after all, including a problem from calling that submit_form function from within the class. There was also an error in the urlencode code for countries. Here's the finished product, which will post to our custom script every time a new item is ordered and paid for. Thanks very much for your help.
PHP Code:
<?php
class orderNotifier extends base {
function orderNotifier() {
# $this->attach($this, array('NOTIFY_CHECKOUT_PROCESS_BEGIN', 'NOTIFY_HEADER_START_CHECKOUT_PAYMENT', 'NOTIFIER_CART_SHOW_TOTAL_START'));
$this->attach($this, array('NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL'));
}
function update(&$Class, $notifier, $paramsArray) {
$num = $paramsArray[0];
$cust = $Class->customer;
$country = urlencode($cust['country']['title']);
foreach ($cust as $k => $v)
if (!is_array($v))
$cust[$k] = urlencode($v);
$inf = $Class->info;
if ($inf['order_status'] == 2) {
foreach($Class->products as $prod) {
$url = 'http://www.yoururl.com/yourpage.php?num=' . $num . '&firstname=' . $cust['firstname'] . '&lastname=' . $cust['lastname'] . '&email=' . $cust['email_address'] . '&company=' . $cust['company'] . '&address=' . $cust['street_address'] . '&city=' . $cust['city'] . '&state=' . $cust['state'] . '&postcode=' . $cust['postcode'] . '&country=' . $country . '&telephone=' . $cust['telephone'] . '&qty=' . $prod['qty'] . '&prod_name=' . urlencode($prod['name']) . '&id=' . urlencode($prod['id']);
$ch = curl_init();
curl_setopt($ch, CURLOPT_INTERFACE, 'yourip');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
}
}
}
}
?>
Re: Sending order data to a script
It looks like y'all knocked this out pretty well. I have a couple of questions, so I can understand how this was accomplished.
Is 'NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL' the event that happens when an admin changes the order status via the drop down in the orders area?
Where does the new php code go? in orders.php somewhere? If so is this really the only file that gets modified in this mod?
Thanks
Paul
Re: Sending order data to a script
How do I find out what other variables are available like this one? $cust['lastname']
For example I'm after customer ID, I'll bet it's $cust['id'], but I imagine there is a defining location for it. I used the DEV tool kit and found all kinds of things, but nothing definate.
Thanks
Paul
Re: Sending order data to a script
Quote:
Originally Posted by
glitzsfa
Is 'NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL' the event that happens when an admin changes the order status via the drop down in the orders area?
No. It's only related to the storefront side. It has nothing to do with the admin side.
If you're targeting admin-related updates, that's a completely separate topic beyond the scope of the discussion in this thread.
Quote:
Originally Posted by
glitzsfa
Where does the new php code go? in orders.php somewhere? If so is this really the only file that gets modified in this mod?
See my first post in this thread, as it contains links to examples which answer that question.
Quote:
Originally Posted by
glitzsfa
How do I find out what other variables are available like this one? $cust['lastname']
You can output your own debug code for seeing what else is in the $cust array by using something like this in your code:
Code:
die('$cust data=' . print_r($cust, true));
Re: Sending order data to a script
I'm successfully sending product information to my external notifier. However, I also need to extract the attributes for a given product. Is there an attributes class under products tha can get me this, or is there another prefered way?
I'm using the code from earlier in this thread.
Re: Sending order data to a script
When hooking the NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL notifier point, the $Class->products array contains many components, including a sub-array of all that product's attributes details. So, you've already got all that information.
Re: Sending order data to a script
Great. I added this and am now sending attributes with the data as well.
foreach($prod['attributes'] as $attr) {
$url .= '&attr_' . $attr['option_id'] . '=' . urlencode($attr['value']);
}
Thanks for the help.
Re: Sending order data to a script
Rather than doing the various print_r's when I'm in 'debug mode', I use the Super Globals plugin and (when enabled) have it dump "all" the superglobals. That way, I've got clues as to the various data elements that were created as part of the page.
Re: Sending order data to a script
That's a cool idea.
One minor problem.
It doesn't seem to be firing when the customer uses Paypal as payment method.
I'm currently using NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL.
Should I be using a different notifier to catch these orders?