0

I've seen multiple people use save_order_place_after, as well as checkout_onepage_controller_success_action. My issue is that I want to do a quick scan of information collected on that order, and update tables depending on the information collected. I've tried both of these events and get the following results (using PayPal Onepage checkout):

save_order_place_after:

  • Blank page loaded (PayPal payment review page according to URL)
  • Order interrupted (no success page)
  • Payment is sent to PayPal successfully
  • No order information is saved anywhere in admin panel or database
  • Account then becomes glitched with "duplicate invoice" error and cannot place another order without receiving error
  • An email is triggered and sent successfully from the Observer.php

checkout_onepage_controller_success_action:

  • Order is successful
  • Success page loaded
  • Nothing is executed from Observer.php

There are no syntax errors in the Observer.php, as it works correctly with the first event but is apparently interrupting the order in some way.

Is there another event that's triggered after an order is successfully completed and saved so that I can scan all information collected on the order?

1

I've only ever had success with checkout_onepage_controller_success_action

       <events>
            <checkout_onepage_controller_success_action>
                <observers>
                    <googleanalytics_order_success>
                        <class>googleanalytics/observer</class>
                        <method>setGoogleAnalyticsOnOrderSuccessPageView</method>
                    </googleanalytics_order_success>
                </observers>
            </checkout_onepage_controller_success_action>
            <checkout_multishipping_controller_success_action>
                <observers>
                    <googleanalytics_order_success>
                        <class>googleanalytics/observer</class>
                        <method>setGoogleAnalyticsOnOrderSuccessPageView</method>
                    </googleanalytics_order_success>
                </observers>
            </checkout_multishipping_controller_success_action>
        </events>

I've updated my observer logic. I think what you've used is the problem.

Observer looks like this

Model/Observer.php

class Mage_GoogleAnalytics_Model_Observer
{
    /**
     * @param Varien_Event_Observer $observer
     */
    public function setGoogleAnalyticsOnOrderSuccessPageView(Varien_Event_Observer $observer)
    {
        $orderIds = $observer->getEvent()->getOrderIds();
        if (empty($orderIds) || !is_array($orderIds)) {
            return;
        }
        // $orderIds is array   
        // do stuff
        foreach($orderIds as $orderId) {
            $order = Mage::getModel('sales/order')->load($orderId);
            // stuff
        }

        // or
        $orders = Mage::getModel('sales/order')
            ->getCollection()
            ->addFieldToFilter('entity_id', array('in' => $orderIds));
        foreach($orders as $order) {
            // stuff
        }

    }
}
  • The only reason I can think of that might cause this event to not work for me is that it might not be grabbing the order ID correctly for some reason? Shouldn't $observer->getEvent()->getOrder(); work just fine when using this event? – taskle Jun 13 at 23:50
  • @taskle I think that might be where you've gone wrong. I've updated my answer. – Dominic Xigen Jun 14 at 0:13
  • I'll have to try this way, but I'm confused as to why this event would require getting the order through a collection loop whereas sales_save_place_after you can get the order by itself. – taskle Jun 14 at 2:21
  • @taskle yep it's how magento works in this case – Dominic Xigen Jun 14 at 13:02
  • When do orders have multiple order IDs? – taskle Jun 14 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.