3

I am using magento 1.7. I would like to have a event before the call of this method Mage_Adminhtml_Sales_Order_CreateController save.

I tried to do it like this :

Config.xml :

 <adminhtml>
        <events>
            <controller_action_predispatch_sales_order_create_save>
                <observers>
                    <gfi_tnt_add_relay_quotes>
                        <type>singleton</type>
                        <class>Gfi_TNT_Model_Observercontroller</class>
                        <method>addTntRelayQuote</method>
                    </gfi_tnt_add_relay_quotes>
                </observers>
            </controller_action_predispatch_sales_order_create_save>
        </events>
</adminhtml>

app/code/community/Gfi/TNT/Model/Observercontroller.php :

class Gfi_TNT_Model_Observercontroller extends Mage_Adminhtml_Controller_Action
{
    public function addTntRelayQuote() {
     ........
    }
}

What is wrong in my code? Could you help me?

1

I assume you are trying to save some custom data after the order is saved from the backend

You can try this event

 <adminhtml>
    <events>
        <sales_order_save_after>
            <observers>
                <gfi_tnt_add_relay_quotes>
                    <type>singleton</type>
                    <class>Gfi_TNT_Model_Observercontroller</class>
                    <method>addTntRelayQuote</method>
                </gfi_tnt_add_relay_quotes>
            </observers>
        </sales_order_save_after>
    </events>
</adminhtml>

Observer

<?php
class Gfi_TNT_Model_Observercontroller
{
    public function addTntRelayQuote() {
        $order = $observer->getEvent()->getOrder();
        // you can use this object and save your additional data
    }
}

You can also try sales_order_save_before event.

  • Indeed , i want to save some custom data on my order. I have informations to save in my session. is it impossible to observer my controller method? But your code seems great , i will try it. Thank you – thomas poidevin Dec 14 '17 at 8:41
0

I found my mistake. With the help of this post : https://stackoverflow.com/questions/31468618/need-a-magento-event-that-will-fire-after-changing-the-shipping-address-of-an-or

I found what was wrong. The name on a controller event in the adminhtml is all the time like this :

<adminhtml>
        <events>
               <controller_action_predispatch_adminhtml_...>
               </controller_action_predispatch_adminhtml_...>
        </events>
</adminhtml>

I thought it was useless to add adminhtml before the path of my controller but not.

So in my case , my config.xml is :

 <adminhtml>
        <events>
                <controller_action_predispatch_adminhtml_sales_order_edit_save>
                    <observers>
                        <gfi_tnt_add_relay_quotesss>
                            <type>singleton</type>
                            <class>Gfi_TNT_Model_Observercontroller</class>
                            <method>addTntRelayQuote</method>
                        </gfi_tnt_add_relay_quotesss>
                    </observers>
                </controller_action_predispatch_adminhtml_sales_order_edit_save>
       </events>
</adminthtml>

I hope it can help :)

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.