0

I am trying to override a core observer, but nothing I have tried has worked. I am trying to observe the event sales_order_save_before. Here is my config file:

Location: app/code/local/DBCustom/Order/etc/config.xml

<config>
    <modules>
        <DBCustom_Order>
            <version>0.1.0</version>
        </DBCustom_Order>
    </modules>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <sales_order_grid>DBCustom_Order_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
                </rewrite>
            </adminhtml>
        </blocks>
        <models>
            <dbcustom_order>
                <class>DBCustom_Order_Model</class>
            </dbcustom_order>
        </models>
        <events>
            <sales_order_save_before>
                <observers>
                    <dbcustom_order_model_observer>
                        <class>DBCustom_Order_Model_Observer</class>
                        <method>salesOrderBeforeSave</method>
                    </dbcustom_order_model_observer>
                </observers>
            </sales_order_save_before>
        </events>
        <!--<events>-->
            <!--<sales_order_save_before>-->
                <!--<observers>-->
                    <!--<dbcustom_order>-->
                        <!--<type>singleton</type>-->
                        <!--<class>dbcustom_order/observer</class>-->
                        <!--<method>beforeSave</method>-->
                    <!--</dbcustom_order>-->
                <!--</observers>-->
            <!--</sales_order_save_before>-->
        <!--</events>-->
    </global>
</config>

And Here is my observer:

Location: app/code/local/DBCustom/Order/Model/Observer.php

<?php

/**
 * Class DBCustom_Order_Model_Observer
 */
class DBCustom_Order_Model_Observer {


    public function salesOrderBeforeSave($observer)
    {
        $order = $observer->getEvent()->getOrder();

        if ($order->getPayment()) {
            if ($order->getPayment()->getMethodInstance()->getCode() != 'free') {
                return $this;
            }
        }
        if ($order->canUnhold()) {
            return $this;
        }

        if ($order->isCanceled() || $order->getState() === Mage_Sales_Model_Order::STATE_CLOSED) {
            return $this;
        }
        /**
         * Allow forced creditmemo just in case if it wasn't defined before
         */
        if (!$order->hasForcedCanCreditmemo()) {
            $order->setForcedCanCreditmemo(true);
        }
        return $this;
    }
}

I have flushed the cache multiple times, but still only goes to the core observer. I have also tried the following naming convention for the observer class as well, and it still didn't work <class>dbcustom_order/observer</class>

The module is active as well, and everything else besides the observers works as intended.

  • Which observer you want to overwrite? – Sohel Rana May 14 at 20:36

Your Answer

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

Browse other questions tagged or ask your own question.