Simple Observer not working
I'm new to Magento and I'm trying to add an additional button to a pre-existing admin form using an observer. I set up my config to what I believe is the right event handle. I created an observer and added the name and method to config. I don't believe my observer is ever hit since Mage log is not printing. Can anyone see where I'm going wrong?
Sales.xml - (Enterprise layout file)
<layout>
<adminhtml_sales_order_view>
<reference name="content">
<block type="adminhtml/sales_order_view" name="sales_order_edit"></block>
</reference>
</adminhtml_sales_order_view>
</layout>
config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Mycompany_MyModule>
<version>0.1.0</version>
</Mycompany_MyModule>
</modules>
<global>
<events>
<adminhtml_sales_order_view>
<observers>
<my_observer>
<type>singleton</type>
<class>Mycompany_MyModule_Model_Observer</class>
<method>addMyButton</method>
</my_observer>
</observers>
</adminhtml_sales_order_view>
</events>
</global>
</config>
Observer.php
<?php
class Mycompany_MyModule_Model_Observer
{
public function addMyButton($observer)
{
Mage::log('test observer');
$container = $observer->getBlock();
if(null !== $container && $container->getType() == 'adminhtml/sales_order_view')
{
$data = array(
'label' => 'My button',
'class' => 'go',
'onclick' => 'setLocation(' ' . Mage::getUrl('*/*', array('param' => 'value')) . '')',
);
$container->addButton('my_button_identifier', $data);
}
return $this;
}
}
event-observer adminhtml magento-1 forms
add a comment |
I'm new to Magento and I'm trying to add an additional button to a pre-existing admin form using an observer. I set up my config to what I believe is the right event handle. I created an observer and added the name and method to config. I don't believe my observer is ever hit since Mage log is not printing. Can anyone see where I'm going wrong?
Sales.xml - (Enterprise layout file)
<layout>
<adminhtml_sales_order_view>
<reference name="content">
<block type="adminhtml/sales_order_view" name="sales_order_edit"></block>
</reference>
</adminhtml_sales_order_view>
</layout>
config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Mycompany_MyModule>
<version>0.1.0</version>
</Mycompany_MyModule>
</modules>
<global>
<events>
<adminhtml_sales_order_view>
<observers>
<my_observer>
<type>singleton</type>
<class>Mycompany_MyModule_Model_Observer</class>
<method>addMyButton</method>
</my_observer>
</observers>
</adminhtml_sales_order_view>
</events>
</global>
</config>
Observer.php
<?php
class Mycompany_MyModule_Model_Observer
{
public function addMyButton($observer)
{
Mage::log('test observer');
$container = $observer->getBlock();
if(null !== $container && $container->getType() == 'adminhtml/sales_order_view')
{
$data = array(
'label' => 'My button',
'class' => 'go',
'onclick' => 'setLocation(' ' . Mage::getUrl('*/*', array('param' => 'value')) . '')',
);
$container->addButton('my_button_identifier', $data);
}
return $this;
}
}
event-observer adminhtml magento-1 forms
add a comment |
I'm new to Magento and I'm trying to add an additional button to a pre-existing admin form using an observer. I set up my config to what I believe is the right event handle. I created an observer and added the name and method to config. I don't believe my observer is ever hit since Mage log is not printing. Can anyone see where I'm going wrong?
Sales.xml - (Enterprise layout file)
<layout>
<adminhtml_sales_order_view>
<reference name="content">
<block type="adminhtml/sales_order_view" name="sales_order_edit"></block>
</reference>
</adminhtml_sales_order_view>
</layout>
config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Mycompany_MyModule>
<version>0.1.0</version>
</Mycompany_MyModule>
</modules>
<global>
<events>
<adminhtml_sales_order_view>
<observers>
<my_observer>
<type>singleton</type>
<class>Mycompany_MyModule_Model_Observer</class>
<method>addMyButton</method>
</my_observer>
</observers>
</adminhtml_sales_order_view>
</events>
</global>
</config>
Observer.php
<?php
class Mycompany_MyModule_Model_Observer
{
public function addMyButton($observer)
{
Mage::log('test observer');
$container = $observer->getBlock();
if(null !== $container && $container->getType() == 'adminhtml/sales_order_view')
{
$data = array(
'label' => 'My button',
'class' => 'go',
'onclick' => 'setLocation(' ' . Mage::getUrl('*/*', array('param' => 'value')) . '')',
);
$container->addButton('my_button_identifier', $data);
}
return $this;
}
}
event-observer adminhtml magento-1 forms
I'm new to Magento and I'm trying to add an additional button to a pre-existing admin form using an observer. I set up my config to what I believe is the right event handle. I created an observer and added the name and method to config. I don't believe my observer is ever hit since Mage log is not printing. Can anyone see where I'm going wrong?
Sales.xml - (Enterprise layout file)
<layout>
<adminhtml_sales_order_view>
<reference name="content">
<block type="adminhtml/sales_order_view" name="sales_order_edit"></block>
</reference>
</adminhtml_sales_order_view>
</layout>
config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Mycompany_MyModule>
<version>0.1.0</version>
</Mycompany_MyModule>
</modules>
<global>
<events>
<adminhtml_sales_order_view>
<observers>
<my_observer>
<type>singleton</type>
<class>Mycompany_MyModule_Model_Observer</class>
<method>addMyButton</method>
</my_observer>
</observers>
</adminhtml_sales_order_view>
</events>
</global>
</config>
Observer.php
<?php
class Mycompany_MyModule_Model_Observer
{
public function addMyButton($observer)
{
Mage::log('test observer');
$container = $observer->getBlock();
if(null !== $container && $container->getType() == 'adminhtml/sales_order_view')
{
$data = array(
'label' => 'My button',
'class' => 'go',
'onclick' => 'setLocation(' ' . Mage::getUrl('*/*', array('param' => 'value')) . '')',
);
$container->addButton('my_button_identifier', $data);
}
return $this;
}
}
event-observer adminhtml magento-1 forms
event-observer adminhtml magento-1 forms
edited Aug 12 '16 at 9:10
Siarhey Uchukhlebau
9,79192858
9,79192858
asked Aug 12 '16 at 3:38
ThisBetterWorkThisBetterWork
1084
1084
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
You need to extend layout instead of writing observer.
You cannot dispatch a new event using layout files. Please check more on how to extend layout handles
Right, I see. I was kind of merging the layout update and observer ideas together. I will check this out now. Thanks.
– ThisBetterWork
Aug 12 '16 at 4:15
add a comment |
There is no event with the name <adminhtml_sales_order_view>
, it is a layout handle.
You need to use event like <core_block_abstract_prepare_layout_before>
as below :
<adminhtml>
<events>
<core_block_abstract_prepare_layout_before>
<observers>
.....
</observers>
</core_block_abstract_prepare_layout_before>
</events>
</adminhtml>
Reference Links :
http://inchoo.net/category/magento/events-observers/
https://www.nicksays.co.uk/magento-events-cheat-sheet-1-9/
Magento add new Button on Sales order view
Thank you for pointing this out. I can't tell if there's a good event that would allow me to append to this admin form. I'm going to checkout layout update, but appreciate your explanation for clarity.
– ThisBetterWork
Aug 12 '16 at 4:18
add a comment |
FINAL CODE - I did a layout update and it worked for me.
config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<MyCompany_MyModule>
<version>0.1.0</version>
</MyCompany_MyModule>
</modules>
<adminhtml>
<layout>
<updates>
<myupdate>
<file>myupdate.xml</file>
</myupdate>
</updates>
</layout>
</adminhtml>
</config>
myupdate.xml
<layout version="0.1.0">
<adminhtml_sales_order_view>
<reference name="sales_order_edit">
<action method="addButton">
<id>my_button_identifier</id>
<data>
<label>My button</label>
<class>go</class>
</data>
</action>
</reference>
</adminhtml_sales_order_view>
</layout>
add a comment |
Have you defined your <blocks>
and <models>
within config.xml? If you didnt define models, that will explain why your observer didn't work. Well, that, and the fact that you have a layout handle as your event.
Additionally, instead of
if(null !== $container && $container->getType() == 'adminhtml/sales_order_view')
you should go with
if($container instanceof Mage_Adminhtml_Block_Sales_Order_View)
That's because if you have some module or customization in the future, the "type" may change but it will most likely still extend from the original class.
Additionally, a super helpful tool created by Alan Storm, Commerce Bug. I use it every single day. In fact, it will provide you with a list of available observer events available on a given page.
Also, xdebug is very helpful when debugging Magento. You will know right away if your observer is firing. I made a short video on how to install xdebug. Xdebug Installation
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f131158%2fsimple-observer-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to extend layout instead of writing observer.
You cannot dispatch a new event using layout files. Please check more on how to extend layout handles
Right, I see. I was kind of merging the layout update and observer ideas together. I will check this out now. Thanks.
– ThisBetterWork
Aug 12 '16 at 4:15
add a comment |
You need to extend layout instead of writing observer.
You cannot dispatch a new event using layout files. Please check more on how to extend layout handles
Right, I see. I was kind of merging the layout update and observer ideas together. I will check this out now. Thanks.
– ThisBetterWork
Aug 12 '16 at 4:15
add a comment |
You need to extend layout instead of writing observer.
You cannot dispatch a new event using layout files. Please check more on how to extend layout handles
You need to extend layout instead of writing observer.
You cannot dispatch a new event using layout files. Please check more on how to extend layout handles
answered Aug 12 '16 at 3:58
shabbirshabbir
18510
18510
Right, I see. I was kind of merging the layout update and observer ideas together. I will check this out now. Thanks.
– ThisBetterWork
Aug 12 '16 at 4:15
add a comment |
Right, I see. I was kind of merging the layout update and observer ideas together. I will check this out now. Thanks.
– ThisBetterWork
Aug 12 '16 at 4:15
Right, I see. I was kind of merging the layout update and observer ideas together. I will check this out now. Thanks.
– ThisBetterWork
Aug 12 '16 at 4:15
Right, I see. I was kind of merging the layout update and observer ideas together. I will check this out now. Thanks.
– ThisBetterWork
Aug 12 '16 at 4:15
add a comment |
There is no event with the name <adminhtml_sales_order_view>
, it is a layout handle.
You need to use event like <core_block_abstract_prepare_layout_before>
as below :
<adminhtml>
<events>
<core_block_abstract_prepare_layout_before>
<observers>
.....
</observers>
</core_block_abstract_prepare_layout_before>
</events>
</adminhtml>
Reference Links :
http://inchoo.net/category/magento/events-observers/
https://www.nicksays.co.uk/magento-events-cheat-sheet-1-9/
Magento add new Button on Sales order view
Thank you for pointing this out. I can't tell if there's a good event that would allow me to append to this admin form. I'm going to checkout layout update, but appreciate your explanation for clarity.
– ThisBetterWork
Aug 12 '16 at 4:18
add a comment |
There is no event with the name <adminhtml_sales_order_view>
, it is a layout handle.
You need to use event like <core_block_abstract_prepare_layout_before>
as below :
<adminhtml>
<events>
<core_block_abstract_prepare_layout_before>
<observers>
.....
</observers>
</core_block_abstract_prepare_layout_before>
</events>
</adminhtml>
Reference Links :
http://inchoo.net/category/magento/events-observers/
https://www.nicksays.co.uk/magento-events-cheat-sheet-1-9/
Magento add new Button on Sales order view
Thank you for pointing this out. I can't tell if there's a good event that would allow me to append to this admin form. I'm going to checkout layout update, but appreciate your explanation for clarity.
– ThisBetterWork
Aug 12 '16 at 4:18
add a comment |
There is no event with the name <adminhtml_sales_order_view>
, it is a layout handle.
You need to use event like <core_block_abstract_prepare_layout_before>
as below :
<adminhtml>
<events>
<core_block_abstract_prepare_layout_before>
<observers>
.....
</observers>
</core_block_abstract_prepare_layout_before>
</events>
</adminhtml>
Reference Links :
http://inchoo.net/category/magento/events-observers/
https://www.nicksays.co.uk/magento-events-cheat-sheet-1-9/
Magento add new Button on Sales order view
There is no event with the name <adminhtml_sales_order_view>
, it is a layout handle.
You need to use event like <core_block_abstract_prepare_layout_before>
as below :
<adminhtml>
<events>
<core_block_abstract_prepare_layout_before>
<observers>
.....
</observers>
</core_block_abstract_prepare_layout_before>
</events>
</adminhtml>
Reference Links :
http://inchoo.net/category/magento/events-observers/
https://www.nicksays.co.uk/magento-events-cheat-sheet-1-9/
Magento add new Button on Sales order view
edited Apr 13 '17 at 12:54
Community♦
1
1
answered Aug 12 '16 at 4:01
Anshu MishraAnshu Mishra
5,33252660
5,33252660
Thank you for pointing this out. I can't tell if there's a good event that would allow me to append to this admin form. I'm going to checkout layout update, but appreciate your explanation for clarity.
– ThisBetterWork
Aug 12 '16 at 4:18
add a comment |
Thank you for pointing this out. I can't tell if there's a good event that would allow me to append to this admin form. I'm going to checkout layout update, but appreciate your explanation for clarity.
– ThisBetterWork
Aug 12 '16 at 4:18
Thank you for pointing this out. I can't tell if there's a good event that would allow me to append to this admin form. I'm going to checkout layout update, but appreciate your explanation for clarity.
– ThisBetterWork
Aug 12 '16 at 4:18
Thank you for pointing this out. I can't tell if there's a good event that would allow me to append to this admin form. I'm going to checkout layout update, but appreciate your explanation for clarity.
– ThisBetterWork
Aug 12 '16 at 4:18
add a comment |
FINAL CODE - I did a layout update and it worked for me.
config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<MyCompany_MyModule>
<version>0.1.0</version>
</MyCompany_MyModule>
</modules>
<adminhtml>
<layout>
<updates>
<myupdate>
<file>myupdate.xml</file>
</myupdate>
</updates>
</layout>
</adminhtml>
</config>
myupdate.xml
<layout version="0.1.0">
<adminhtml_sales_order_view>
<reference name="sales_order_edit">
<action method="addButton">
<id>my_button_identifier</id>
<data>
<label>My button</label>
<class>go</class>
</data>
</action>
</reference>
</adminhtml_sales_order_view>
</layout>
add a comment |
FINAL CODE - I did a layout update and it worked for me.
config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<MyCompany_MyModule>
<version>0.1.0</version>
</MyCompany_MyModule>
</modules>
<adminhtml>
<layout>
<updates>
<myupdate>
<file>myupdate.xml</file>
</myupdate>
</updates>
</layout>
</adminhtml>
</config>
myupdate.xml
<layout version="0.1.0">
<adminhtml_sales_order_view>
<reference name="sales_order_edit">
<action method="addButton">
<id>my_button_identifier</id>
<data>
<label>My button</label>
<class>go</class>
</data>
</action>
</reference>
</adminhtml_sales_order_view>
</layout>
add a comment |
FINAL CODE - I did a layout update and it worked for me.
config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<MyCompany_MyModule>
<version>0.1.0</version>
</MyCompany_MyModule>
</modules>
<adminhtml>
<layout>
<updates>
<myupdate>
<file>myupdate.xml</file>
</myupdate>
</updates>
</layout>
</adminhtml>
</config>
myupdate.xml
<layout version="0.1.0">
<adminhtml_sales_order_view>
<reference name="sales_order_edit">
<action method="addButton">
<id>my_button_identifier</id>
<data>
<label>My button</label>
<class>go</class>
</data>
</action>
</reference>
</adminhtml_sales_order_view>
</layout>
FINAL CODE - I did a layout update and it worked for me.
config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<MyCompany_MyModule>
<version>0.1.0</version>
</MyCompany_MyModule>
</modules>
<adminhtml>
<layout>
<updates>
<myupdate>
<file>myupdate.xml</file>
</myupdate>
</updates>
</layout>
</adminhtml>
</config>
myupdate.xml
<layout version="0.1.0">
<adminhtml_sales_order_view>
<reference name="sales_order_edit">
<action method="addButton">
<id>my_button_identifier</id>
<data>
<label>My button</label>
<class>go</class>
</data>
</action>
</reference>
</adminhtml_sales_order_view>
</layout>
answered Aug 12 '16 at 4:45
ThisBetterWorkThisBetterWork
1084
1084
add a comment |
add a comment |
Have you defined your <blocks>
and <models>
within config.xml? If you didnt define models, that will explain why your observer didn't work. Well, that, and the fact that you have a layout handle as your event.
Additionally, instead of
if(null !== $container && $container->getType() == 'adminhtml/sales_order_view')
you should go with
if($container instanceof Mage_Adminhtml_Block_Sales_Order_View)
That's because if you have some module or customization in the future, the "type" may change but it will most likely still extend from the original class.
Additionally, a super helpful tool created by Alan Storm, Commerce Bug. I use it every single day. In fact, it will provide you with a list of available observer events available on a given page.
Also, xdebug is very helpful when debugging Magento. You will know right away if your observer is firing. I made a short video on how to install xdebug. Xdebug Installation
add a comment |
Have you defined your <blocks>
and <models>
within config.xml? If you didnt define models, that will explain why your observer didn't work. Well, that, and the fact that you have a layout handle as your event.
Additionally, instead of
if(null !== $container && $container->getType() == 'adminhtml/sales_order_view')
you should go with
if($container instanceof Mage_Adminhtml_Block_Sales_Order_View)
That's because if you have some module or customization in the future, the "type" may change but it will most likely still extend from the original class.
Additionally, a super helpful tool created by Alan Storm, Commerce Bug. I use it every single day. In fact, it will provide you with a list of available observer events available on a given page.
Also, xdebug is very helpful when debugging Magento. You will know right away if your observer is firing. I made a short video on how to install xdebug. Xdebug Installation
add a comment |
Have you defined your <blocks>
and <models>
within config.xml? If you didnt define models, that will explain why your observer didn't work. Well, that, and the fact that you have a layout handle as your event.
Additionally, instead of
if(null !== $container && $container->getType() == 'adminhtml/sales_order_view')
you should go with
if($container instanceof Mage_Adminhtml_Block_Sales_Order_View)
That's because if you have some module or customization in the future, the "type" may change but it will most likely still extend from the original class.
Additionally, a super helpful tool created by Alan Storm, Commerce Bug. I use it every single day. In fact, it will provide you with a list of available observer events available on a given page.
Also, xdebug is very helpful when debugging Magento. You will know right away if your observer is firing. I made a short video on how to install xdebug. Xdebug Installation
Have you defined your <blocks>
and <models>
within config.xml? If you didnt define models, that will explain why your observer didn't work. Well, that, and the fact that you have a layout handle as your event.
Additionally, instead of
if(null !== $container && $container->getType() == 'adminhtml/sales_order_view')
you should go with
if($container instanceof Mage_Adminhtml_Block_Sales_Order_View)
That's because if you have some module or customization in the future, the "type" may change but it will most likely still extend from the original class.
Additionally, a super helpful tool created by Alan Storm, Commerce Bug. I use it every single day. In fact, it will provide you with a list of available observer events available on a given page.
Also, xdebug is very helpful when debugging Magento. You will know right away if your observer is firing. I made a short video on how to install xdebug. Xdebug Installation
edited 36 mins ago
Teja Bhagavan Kollepara
2,96341847
2,96341847
answered Aug 12 '16 at 5:41
Shawn AbramsonShawn Abramson
2,4771915
2,4771915
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f131158%2fsimple-observer-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown