1

Recently in the development of a Magento site the setHasDownloadableProducts($observer) method has stopped running when the checkout_type_onepage_save_order_after event is fired.

Unfortunately I can't pinpoint exactly when it stopped but I do know that it was working previously.

I am certain the event is firing thanks to Mage::Log on the dispatchEvent() method; it records the event whenever a user completes the checkout, just as it should.

I'm also confident the event is firing as I have attached a custom method to the same event and that runs great.

Has anyone seen anything like this? I'm not sure where to look really, apart from the obvious (the Mage_Downloadable extension is enabled) because I haven't knowingly made any changes to the code in this area.

UPDATE: So, I found that if I remove my custom method which is attached to the same event, the original runs as it should... Should both attached methods run when the event is fired?

I found something on this site which suggested adding <depends><Mage_Downloadable/></depends> to the app/etc/modules XML file but this made no difference, the custom method still seems to override the in built method.

UPDATE 2: Okay, so I've worked round this by simply attaching my custom method to a suitable nearby event, sales_order_save_commit_after. Would still like some insight on why this didn't work in the first case though and if my workaround will have any unintended consequences... Thanks for reading!

UPDATE 3: As requested, here is the config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Company_Extension>
            <version>0.1.0</version>
        </Company_Extension>
    </modules>
    <global>
        <helpers>
            <company_extension>
                <class>Company_Extension_Helper</class>
            </company_extension>
        </helpers>
        <blocks>
            <extension>
                <class>Company_Extension_Block</class>
            </extension>
        </blocks>
        <models>
            <company_extension>
                <class>Company_Extension_Model</class>
            </company_extension>
        </models>
    </global>
    <frontend>
        <events>
            <sales_order_save_commit_after>
                <observers>
                    <sales_order_save_commit_after>
                        <class>company_extension/observer</class>
                        <method>setHasSpecificProducts</method>
                    </sales_order_save_commit_after>
                </observers>
            </sales_order_save_commit_after>
        </events>
    </frontend>
</config>

As mentioned previously, the sales_order_save_commit_after event was checkout_type_onepage_save_order_after but this failed to run as I'm already using it in another module.

The observer code is as follows:

<?php

class Company_Extension_Model_Observer
{
    public $SpecificProducts = array(1,2,3);
    /**
     * Set checkout session flag if order has specific product(s)
     *
     * @param Varien_Object $observer
     * @return Company_Extension_Model_Observer
     */
    public function setHasSpecificProducts($observer)
    {
        Mage::log("Called setHasSpecificProducts()", null, 'Company.log', true);
        $session = Mage::getSingleton('checkout/session');
        if (!$session->getHasSpecificProducts()) {
            $order = $observer->getEvent()->getOrder();
            /* @var $item Mage_Sales_Model_Order_Item */
            foreach ($order->getAllItems() as $item) {
                Mage::log("Found order item", null, 'Company.log', true);
                $full_item = Mage::getModel('catalog/product')->load($item->getProductId());

                if (in_array($full_item->getId(),$this->SpecificProducts))
                {
                    Mage::log("Specific order item found", null, 'Company.log', true);
                    $session->setHasSpecificProducts(true);
                    break;
                }
            }
        }
    }
}

closed as too broad by Anna Völkl, Marius Feb 15 '15 at 18:25

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Could you post your config.xml and observer code so that we can help you out? – David Manners Jun 19 '14 at 8:10