Rob
Rob

Reputation: 957

Call new php function when order is complete in Magento

I have a magento site for ecommerce. When an order is placed, I need to call another function I've created in a new php file and pass the order skus, quantities and shipping address to. I'm extremely comfortable with php, but Magento is an entirely new beast for me.

Does anyone know how to call a function when an order is placed? Even just the name of the event would be helpful.

Upvotes: 2

Views: 942

Answers (2)

Justus Krapp
Justus Krapp

Reputation: 1116

you can try sales_order_place_before and sales_order_place_after

if you are interested in the events fired, a common approach is to temporary add Mage::log($name); in the Mage.php (app/Mage.php) like this

public static function dispatchEvent($name, array $data = array())
{
    Mage::log($name);
    Varien_Profiler::start('DISPATCH EVENT:'.$name);
    $result = self::app()->dispatchEvent($name, $data);
    Varien_Profiler::stop('DISPATCH EVENT:'.$name);
    return $result;
}

this will log any event fired during a page view or action to the var/log/system.log, if you enabled logging in the backend System->Configuration>Developer->Log Settings

Upvotes: 2

Mike
Mike

Reputation: 2136

I haven't used it personally, but sales_order_place_after sounds like it might be what you're looking for. It's used in this way in this Inchoo article, which also involves doing some things as soon as an order is placed.

Here's a page on the Magento wiki about setting up an event observer, which really is just a little XML to tell Magento to run some code when that event is dispatched, and the code you want to run.

Upvotes: 3

Related Questions