开发者

Magento Event Model question

开发者 https://www.devze.com 2023-03-28 14:58 出处:网络
I\'m pretty newbie on the Magento stuff and right now I\'m lock in one thing. I\'ve been trying to understand the Magento\'s event model and I found this line:

I'm pretty newbie on the Magento stuff and right now I'm lock in one thing. I've been trying to understand the Magento's event model and I found this line:

    Mage::dispatchEvent('payment_method_is_active', array(
        'result'          => $checkResult,
        'method_instance' => $this,
        'quote'           => $quote,
    ));

Now, I understand that the dispatchEvent calls the event with the name "开发者_如何学Cpayment_method_is_active", the problem is I can't find this event nowhere. I thought it should be in Mage->Payment->Model->Method-> , but I can't find it until now.

Could you help me on this?


Actually, the code you've put isn't calling the event but dispatching it, so that other module can listen to it.
In this case, this event is listened by the Sales module: you can check that by opening the app/code/core/Mage/Sales/etc/config.xml, inside the tag <events> (inside <adminhtml>), you'll see:

        <payment_method_is_active>
            <observers>
                <sales_billing_agreement>
                    <class>sales/observer</class>
                    <method>restrictAdminBillingAgreementUsage</method>
                </sales_billing_agreement>
            </observers>
        </payment_method_is_active>

You can see that the first tag matches the name of the event (payment_method_is_active).
sales_billing_agreement is just a name to identify the observation.
<class>sales/observer</class> tells you that the file which contains the method is Mage_Sales_Model_Observer.
And <method>restrictAdminBillingAgreementUsage</method> is the name of the method in this file that take some action when the event is dispatched and work with.
Having a look at this method, you'll see that it takes one parameter, $observer and that throufh that $observer you can access to the data set in the event, ie: to access 'result' -> $methodInstance = $observer->getEvent()->getMethodInstance();

Hope That Helps


You will not find any class or method that represents this event. You can define in your modules config.xml that you want to observe this event and what method should be called whenever this event is fired. For more information about Magento Event Observer e.g. look at http://codemagento.com/2011/04/observers-and-dispatching-events/.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号