Nick Parsons
Nick Parsons

Reputation: 8607

Magento observer throwing error

I'm attempting to subscribe to the sales_order_place_after observer in Magento so that I can output order data. Unfortunately, anytime I try to log output to Mage::log, print_r, or even var_dump, I receive a User Error: Some transactions have not been committed or rolled back error.

It's probably also important to note that I'm using one step checkout and the checkout usually hangs (confirmation email still comes through). Shortly after the hang, I receive a PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 234881024 bytes) error. Can't seem to track down where or what is causing the memory leak... but it this error is only spit out if I am trying to output data.

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <InfinitelyWhite_OrderEvent>
            <version>0.0.1</version>
        </InfinitelyWhite_OrderEvent>
    </modules>

<!-- Configure our module's behavior in the global scope -->
<global>

    <!-- Defining models -->
    <models>

        <!--
            Unique identifier in the model's node.
            By convention, we put the module's name in lowercase.
        -->
        <infinitelywhite_orderevent>

            <!--
                The path to our models directory, with directory
                separators replaced by underscores
            -->
            <class>InfinitelyWhite_OrderEvent_Model</class>

        </infinitelywhite_orderevent>

    </models>

    <events>
        <sales_order_place_after>
            <observers>
                <infinitelywhite_orderevent>
                    <class>infinitelywhite_orderevent/observer</class>
                    <method>exportNewOrder</method>
                    <type>singleton</type>
                </infinitelywhite_orderevent >
            </observers>
        </sales_order_place_after>
    </events>

</global>

Observer.php

class InfinitelyWhite_OrderEvent_Model_Observer
{
    /**
     * Magento passes a Varien_Event_Observer object as
     * the first parameter of dispatched events.
     */
    public function exportNewOrder(Varien_Event_Observer $observer) 
    {

        Mage::log('reached export_new_order');

        $order = $observer->getOrder();

        Mage::log($order->getData());

        return $this;

    }
}

Any help would be greatly appreciated.

Upvotes: 0

Views: 3118

Answers (3)

Nick Parsons
Nick Parsons

Reputation: 8607

Turns out the error was coming up because I was attempting to pull order information with $observer->getOrder(), when the correct approach is to use $observer->getEvent()->getOrder(). I was simply missing the getEvent().

I'm now able to extract data like so:

$order = $observer->getEvent()->getOrder();
$billing = $order->getBillingAddress();
$shipping = $order->getShippingAddress();
$customer = $order->getCustomer();

And then I can do something like:

$order->getData() or $customer->getData()

It's also important to note that because I switched up my observer event and I'm not using sales_model_service_quote_submit_success which stopped the nasty User Error: Some transactions have not been committed or rolled back error.

Upvotes: 1

Mike
Mike

Reputation: 141

Can't comment yet, but what happens if you disable your observer? (Just to make sure it is the observer causing this issue).

If it is the observer, you could try replacing $order->getData() with $order->debug() and see if that helps

Upvotes: 0

Amit Bera
Amit Bera

Reputation: 7611

Nick Parson .....please removed singleton

<type>singleton</type>

Upvotes: 1

Related Questions