Reputation: 662
I am currently creating a module that allows a back end user to manage customer's allowed payment methods. Magento event/observer helps a lot - everything that I need to do about customers hooked nicely by this system and transfers to my code. But I also need to hook an event of payment method creation (registering new payment method module). I know that there is no such event in Magento (correct me if I'm wrong), but I need some workaround to achieve such a functionality (nice/right way).
So here is a question:
What is the best (nice/right) way to manage (hook) an event of payment method creation (payment module registering) in Magento?
Sorry for the bad language... Thanks for answers!
Upvotes: 0
Views: 552
Reputation: 3797
You might research about module installation. Particularly, all modules are inserted into database:
core_resource
Also I would suggest to start from:
Mage_Core_Model_Resource_Setup
Also perhaps debug_backtrace() would help you. When you place your module first time you can backtrace how it was installed.
UPDATE 1
Try to trace following functions:
/**
* Processing object after save data
*
* @return Mage_Core_Model_Abstract
*/
protected function _afterSave()
{
/**
* Callback function which called after transaction commit in resource model
*
* @return Mage_Core_Model_Abstract
*/
public function afterCommitCallback()
{
/**
* Get array of objects transfered to default events processing
*
* @return array
*/
protected function _getEventData()
{
Well please specify you last goal. Perhaps there is far more better solution than via observers.
Upvotes: 1
Reputation: 23205
Module install occurs quite early in application initialization; in fact, it occurs before the event areas are parsed, so there is no way to trigger the event observer. See Mage_Core_Model_App::run()
. Notice how loadAreaPart()
(which triggers loading of event observer configuration) is called after _initModules()
(in which we find the module install call Mage_Core_Model_Resource_Setup::applyAllUpdates()
). Standard event dispatching would therefore be pointless.
From a general app design perspective I'd argue that using Magento's event-driven architecture for this purpose is overkill. With any module install you are necessarily touching the database. Rather than have a generic observer looking at all module installs, you should implement your own resource setup class which extends from Mage_Core_Model_Resource_Setup
- several core modules do this. In this custom setup resource class you can perform any task for which you are currently considering (sending an email, logging some info, writing an additional record to the DB, etc.). From here it will be up to you and your developers to require that each new payment module use this setup resource to install payment modules.
Upvotes: 2