Magento only the last event is executed - magento

i have a small problem. I have register two events, but only the last was alwas called,
can someone help me
<!-- Events -->
<events>
<checkout_type_onepage_save_order_after>
<observers>
<save_after>
<type>singleton</type>
<class>XXX_testr_Model_Observer_OrderObserver</class>
<method>orderSubmitEvent</method>
</save_after>
</observers>
</checkout_type_onepage_save_order_after>
<customer_save_after>
<observers>
<XXX_testr_observer_observer>
<type>singleton</type>
<class>XXX_testr_Model_Observer_Observer</class>
<method>customerSaveEvent</method>
</XXX_testr_observer_observer>
</observers>
</customer_save_after>
</events>

At first glance it could possibly be an observer name clash, try namespacing it to be unique
try changing:
save_after
to:
sdz_wawiconnector_observer_save_after

Depending on your usage, you might have more luck working with the controller thrown event checkout_onepage_controller_success_action.

Firstly, I can tell that your xml is valid.
Check such things:
duplicates of observer names (may be save_after or XXX_testr_observer_observer have already exist)
Look to the section, where you put these observers and there you want them to be executed. For example, you put them into frontend section, so customer_save_after will not run in admin.
Make a check if some other observer (from 3rd party extensions) do not crashes before. Or, for example, it can use 'die' in its code.
Check if some other extension rewrites core model/controller (or your store have such rewrite in app/code/local/Mage/.. section) and doesn't have event dispatcher in its code

Related

Magento - How can i run function when the checkout page is opened?

I am using Magento 1.9.2 and i am working on a custom extension.
My question is:
How can i run custom php function when the checkout page is opened?
I know i have to mess around with the events of the extension config file but i am not exactly sure how i can point the function in the observer which i want to run when the checkout page is opened.
Here is events part of my config:
<events>
<controller_action_postdispatch_opc_json_saveOrder>
<observers>
<hss_save_order_onepage>
<class>paypal/observer</class>
<method>setResponseAfterSaveOrder</method>
</hss_save_order_onepage>
</observers>
</controller_action_postdispatch_opc_json_saveOrder>
<sales_order_place_before>
<observers>
<custom_ads>
<class>opc/observer</class>
<method>checkitemsincartv</method>
</custom_ads>
</observers>
</sales_order_place_before>
<sales_order_place_after>
<observers>
<newsletter_order_place_after>
<class>opc/observer</class>
<method>newsletter</method>
</newsletter_order_place_after>
</observers>
</sales_order_place_after>
<checkout_submit_all_after>
<observers>
<opc_checkout_submit_all_after>
<class>opc/observer</class>
<method>applyComment</method>
</opc_checkout_submit_all_after>
</observers>
</checkout_submit_all_after>
</events>
Here is the function that i want to run:
public function checkitemsincartv($observer)
{
Mage::getSingleton('core/session')->setItemsInCart("Works");
$data = $observer->getEvent()->getOrder();
Mage::log($data->debug(), null, "order.log", true);
}
How can i achieve that?
Thanks in advance!
You need to use the event - controller_action_predispatch_checkout_onepage_index or controller_action_postdispatch_checkout_onepage_index All controllers inherit the preDispatch or postDispatch method which fires a generic event for predispatch/postdispatch, and a specific event based on the requested action path.
The controller you need is in the checkout module and is called onepage with a default action of index.
Checkout Mage_Core_Controller_Varien_Action::preDispatch() or Mage_Core_Controller_Varien_Action::postDispatch() to see the relevant code

Magento observer doesnt respond to customer_logout

I am using Magento 1.7.0.2 (old but this isn't a post about telling me to upgrade please, its not practical right now).
I have an observer which works as expected for every event I am interested in however for some reason attempting to respond to customer_logout doesn't work.
I have the following set up:
<!--LOGOUT (doesnt)-->
<customer_logout>
<observers>
<analytics_logout>
<class>analytics/observer</class>
<method>logCustomerLogout</method>
<type>singleton</type>
</analytics_logout>
</observers>
</customer_logout>
<!--LOGIN (Works)-->
<customer_login>
<observers>
<analytics_login>
<class>analytics/observer</class>
<method>logCustomerLogin</method>
<type>singleton</type>
</analytics_login>
</observers>
</customer_login>
Where the logCustomerLogout function is:
public function logCustomerLogout(Varien_Event_Observer $observer)
{
Mage::getSingleton('core/session')->setData('someTagType', 'CustomerLogout');
}
I added logging to app/Mage.php to log to the console each event on DispatchEvent and the console shows the event is coming through as customer_logout so I don't understand what is going on.
Any ideas?
Since you have logged the output, it does fire. The only logical conclusion would be that some other event that is listening to it prevents it from reaching yours. I would suggest to find those events and log their call - see what is the last one it calls and obviously that is where it stops.

Magento Lost Style after checkout_onepage_controller_success_action

<events>
<checkout_onepage_controller_success_action>
<observers>
<sendmail>
<type>singleton</type>
<class>Xkey_Redegrupo_Model_Observer</class>
<method>sendMailRGroup</method>
</sendmail>
</observers>
</checkout_onepage_controller_success_action>
</events>
If I change the checkout_onepage_controller_success_action to sales_order_after_save, work but send 2 times the e-mail, when I use this, the e-mail sends succefull but the layout of /onepage/checkout/success/ lost style ? Why? ! help me Ç.Ç
Kin checkout_onepage_controller_success_action is an event is occur after order has successfully place and redirected to checkout/onepage/success pages.it an fronted event.sales_order_after_save is global event and it is run when you save order. several time are occurs during order procedure....
Exmple of event
<checkout_onepage_controller_success_action>
<observers>
<create_invoice_for_zero_payment>
<class>zerosubtotalpaymentmethod/createinvoice</class>
<method>automaticinovoice</method>
</create_invoice_for_zero_payment>
</observers>
</checkout_onepage_controller_success_action>

Custom "Catalog Input Type for Store Owner" for magento product attributes

In magento you can create new attributes (which are then added to attribute sets which products inherit) with certain types.
The default options (textfield/area, data, boolean) are fairly limited and I would like to add my own, complete with backend field renderer and its own validation. This to create a youtube field which accepts a range of urls which are transformed into only the youtube id.
But I'd really like a good explanation on how to add your own "Catalog Input Type for Store Owner". I've seen other plugins do it, but digging through code is tedious and this is definitely something which interests other people as well (question gets asked a lot over the web).
I have been searching for a while, but to no avail, I will continue to hunt down the answer until I find it however.
tl;dr
So my question is: How to add a "Catalog Input Type for Store Owner", maybe with a reference how to add a custom validation to this field type. This in the proper MVC style, so no editing of core files if possible.
Bonus points for being elaborate, generic explanations & code examples, I will award a bounty based on the quality of answer, if it is worth it (since this will be applicable to a larger audience).
Sorry, I don't have time for writing long answer. Next 4 observers from Wee module will give you needed directions:
<config>
<global>
<events>
<catalog_entity_attribute_save_before>
<observers>
<weee>
<type>model</type>
<class>weee/observer</class>
<method>assignBackendModelToAttribute</method>
</weee>
</observers>
</catalog_entity_attribute_save_before>
</events>
</global>
...
<adminhtml>
<events>
<adminhtml_catalog_product_edit_prepare_form>
<observers>
<weee>
<class>weee/observer</class>
<method>setWeeeRendererInForm</method>
</weee>
</observers>
</adminhtml_catalog_product_edit_prepare_form>
<adminhtml_product_attribute_types>
<observers>
<weee>
<type>model</type>
<class>weee/observer</class>
<method>addWeeeTaxAttributeType</method>
</weee>
</observers>
</adminhtml_product_attribute_types>
<adminhtml_catalog_product_edit_element_types>
<observers>
<weee>
<class>weee/observer</class>
<method>updateElementTypes</method>
</weee>
</observers>
</adminhtml_catalog_product_edit_element_types>
</events>
</adminhtml>
</config>

Make a custom observer fire before an existing Magento observer

Is there a way to make an observer that you have custom made have higher priority than the Magento one that fires on the same event. My problem is I am modifying the output of the Welcome block but the PageCache for enterprise fires on the same corecore_block_abstract_to_html_after event.
I tried putting this in my config but it didn't work like cron jobs do.
<core_block_abstract_to_html_after>
<observers>
<modify_welcome>
<type>singleton</type>
<class>groupname_page/observer</class>
<method>changeWelcomeText</method>
</modify_welcome>
<enterprise_pagecache>
<class>enterprise_pagecache/observer</class>
<method>renderBlockPlaceholder</method>
</enterprise_pagecache>
</observers>
</core_block_abstract_to_html_after>
/app/etc/modules/Groupname_Page.xml
<config>
<modules>
<Groupname_Page>
<active>true</active>
<codePool>local</codePool>
<depends>
<!-- Your dependencies go here -->
</depends>
</Groupname_Page>
<Enterprise_PageCache>
<depends>
<Groupname_Page />
</depends>
</Enterprise_PageCache>
</modules>
</config>
There is no way to control order of observers.
If you take a look on the Mage_Core_Model_App::dispatchEvent() method, you'll see how Magento get all observers for a given event from config.xml files and fires them one by one.
Rewriting the Welcome block will help you.
another option is to disable the enterprise cache observer and in your own observer run the method that would have been executed by the disabled observer
In your module's config.xml:
<core_block_abstract_to_html_after>
<observers>
<modify_welcome>
<type>singleton</type>
<class>groupname_page/observer</class>
<method>changeWelcomeText</method>
</modify_welcome>
<enterprise_pagecache>
<type>disabled</type>
</enterprise_pagecache>
</observers>
</core_block_abstract_to_html_after>
And in your Observer.php:
public function changeWelcomeText(Varien_Event_Observer $observer)
{
//do the stuff you want your observer to do first
//and after it's done, call the Enterprise observer's method
Mage::getSingleton('enterprise_pagecache/observer')->renderBlockPlaceholder($observer);
}
HTH

Resources