predispatch on a adminthml controller
-
21-12-2020 - |
题
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?
解决方案 2
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 :)
其他提示
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.