Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Event dispatch requests
 
Vinai
Sr. Member
 
Avatar
Total Posts:  218
Joined:  2008-04-04
Heidelberg, Germany
 

I would like to expand on my previous event request http://www.magentocommerce.com/boards/viewreply/54377/ , where I only asked for a event in case of a product collection load.
Having a general event fire before a collection is loaded (not only for product collections)

Mage::dispatchEvent('collection_load_before', array('collection' => $collection))
would be very useful.
My suggestion would be to add it to Mage_Catalog_Model_Resource_Eav_Mysql4_Collection_Abstract::_beforeLoad()

Thanks!
Vinai

 
Magento Community Magento Community
Magento Community
Magento Community
 
lostbens
Member
 
Total Posts:  31
Joined:  2008-09-04
 

Guys

I don’t know what to say - these events rock! smile This solves a problem I’ve been wrestling with for two days, and to think I stumbled upon this thread by accident… I promise to help an old lady across the street on the way home.

One question on the observer function: what is passed in the $observer parameter? Moshes example cites $observer->getOrder() and $observer->getCustomer() - these didn’t work for me. Is there any documentation on how we can use this object?

Cheers,

Ben.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vinai
Sr. Member
 
Avatar
Total Posts:  218
Joined:  2008-04-04
Heidelberg, Germany
 

@lostbens - The objects passed to the observer depend on context of the event. most of the time the “things” you need are right there.
if you grep for the matching dispatchEvent() call you can see what’s being passed.
Vinai

 
Magento Community Magento Community
Magento Community
Magento Community
 
lbourrel
Jr. Member
 
Avatar
Total Posts:  26
Joined:  2008-06-09
Ayaline - Poitiers
 

lostbens,

The parameter depends of the event.

For example, in core/Mage/Checkout/Model/Cart.php you can find :
Mage::dispatchEvent(’checkout_cart_product_add_after’, array(’quote_item’=>$result, ‘product’=>$product));
This means that the event ‘checkout_cart_product_add_after’ is called with two params : quote_item and product. You can call them in your event with :
$observer->getEvent()->getQuoteItem() and $observer->getEvent()->getProduct()

An other example when you save a model :
In app\code\core\Mage\Core\Model\Abstract.php you can find :
Mage::dispatchEvent($this->_eventPrefix.’_save_before’, array($this->_eventObject=>$this));
So, the parameter depends of your model. You must look the _eventPrefix of your model.
If it’s a catalog/product, your call will be :
$observer->getEvent()->getProduct()

HTH…

 
Magento Community Magento Community
Magento Community
Magento Community
 
lostbens
Member
 
Total Posts:  31
Joined:  2008-09-04
 

Hey Vinai

from Mage/checkout/controllers/OnepageController.php (line 166):

Mage::dispatchEvent(’checkout_onepage_controller_success_action’);

what’s being passed???!

B.

ps I played around with the $observer object to see what I could grab, but I was fumbling in the dark, in the end I retrieved the order using:
$orderId = Mage::getSingleton(’checkout/session’)->getLastRealOrderId();
$order = Mage::getModel(’sales/order’)->loadByIncrementId($orderId);
but to be honest I have no idea if this is the best way of retrieving the order - it just seems to do the trick in the few cases I’ve tested so far.

 
Magento Community Magento Community
Magento Community
Magento Community
 
lostbens
Member
 
Total Posts:  31
Joined:  2008-09-04
 

Laurent thanks

looks like for the example I was using there is nothing passed - maybe not the best event to get started with… wink

B.

 
Magento Community Magento Community
Magento Community
Magento Community
 
skippybosco
Enthusiast
 
Avatar
Total Posts:  796
Joined:  2008-10-03
 

Can anyone point me in the right direction of what is the best events for when a new user is created.

(bonus points if you know the event for when they login and logout as I’m trying to populate a cookie for a 3rd party app)

Thanks!

S

 
Magento Community Magento Community
Magento Community
Magento Community
 
lbourrel
Jr. Member
 
Avatar
Total Posts:  26
Joined:  2008-06-09
Ayaline - Poitiers
 

Skippy,

Do you talk about “admin user” or “customer” ?

If customer, then you can use :
customer_login
customer_logout
customer_save_after

If admin user, then you can use…
well… there’s not !

So first way :
for login/logout : override Mage_Adminhtml_IndexController and add a dispatchEvent of your own.
for save : same but with Mage_Adminhtml_Permissions_UserController.
Another way :
perhaps you can use the event controller_action_postdispatch_{action_name}, but i’m not sure you will have all informations that you need.

Hope this helps and i will have extra points… grin

 
Magento Community Magento Community
Magento Community
Magento Community
 
skippybosco
Enthusiast
 
Avatar
Total Posts:  796
Joined:  2008-10-03
 

Thanks so much Laurent, I’ll code this up now in my 1.2 sandbox and see how it goes!

Regardless of the outcome, extra points for the response time alone.

Cheers!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vinai
Sr. Member
 
Avatar
Total Posts:  218
Joined:  2008-04-04
Heidelberg, Germany
 

Back OT: another event request:

Mage::dispatchEvent('groupscatalog_layer_fiter_items_init_after', array('filter' => $this'items' => &$this->_items));
in Mage_Catalog_Model_Layer_Filter_Abstract::_initItems() would be quite helpful.

Thanks,
Vinai

EDIT: stupid idea, would not work the way I posted. but something along these lines to work on the filter items would be nice.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vinai
Sr. Member
 
Avatar
Total Posts:  218
Joined:  2008-04-04
Heidelberg, Germany
 

I’m wondering, will there be an update on when or which of these events will be implemented in the core?
It’s been a couple of releases for some of the requests..

Vinai

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vinai
Sr. Member
 
Avatar
Total Posts:  218
Joined:  2008-04-04
Heidelberg, Germany
 

I’m Back!  grin
I’m getting lots of conflicts between modules overriding Blocks.
So, how about changing the core_block_abstract_to_html_after event in Mage_Core_Block_Abstract::toHtml() to something where actual html could be injected / filtered / converted?

$html $this->_afterToHtml($html);
$this->setHtml($html);
Mage::dispatchEvent('core_block_abstract_to_html_after', array('block' => $this));
return 
$this->getHtml();

I suggest adding a block specific event, too.

if ($this->_eventPrefixMage::dispatchEvent($this->_eventPrefix'_to_html_after', array('block' => $this));

Thanks,

Vinai

 
Magento Community Magento Community
Magento Community
Magento Community
 
retif
Sr. Member
 
Total Posts:  171
Joined:  2008-08-16
Odessa, Ukraine
 

requesting events to implement proper integration of firephp

1.
file: \app\code\core\Mage\Core\Controller\Varien\Front.php

function: public function dispatch()

before: $this->getResponse()->sendResponse();

event: Mage::dispatchEvent(’controller_front_before_sendresponse’, array(’front’=>$this));

i need this to flush firephp headers to response object

2.
file: /app/Mage.php

function: public static function log($message, $level=null, $file = ‘’)

after:
if (!Mage::getStoreConfig(’dev/log/active’)) {
return;
}

event: Mage::dispatchEvent(’mage_log’, array(’message’=>$message, ‘leve’=>$level, ‘file’=>$file));

i need that to intercept all logs and serve them with firephp

that two events will make possible using firephp logging features, but without firephp db queries profiler.

i maked firephp query profiler to work by adding one line to getConnection function of Mage_Core_Model_Resource_Type_Db_Pdo_Mysql
becouse firephp need array type of profiler key
$configArr[’profiler’] = (array)$configArr[’profiler’];

 
Magento Community Magento Community
Magento Community
Magento Community
 
lbourrel
Jr. Member
 
Avatar
Total Posts:  26
Joined:  2008-06-09
Ayaline - Poitiers
 

Hi,

You can find the list of events for the v1.2.0.2 :

http://www.magentocommerce.com/wiki/customizing_magento_using_event-observer_method#events

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vinai
Sr. Member
 
Avatar
Total Posts:  218
Joined:  2008-04-04
Heidelberg, Germany
 

Please add the following event, analog to the existing checkout_onepage_controller_success_action:

Mage::dispatchEvent('checkout_multishipping_controller_success_action')

Thanks,
Vinai

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top