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

Can anybody explain me this code? 
 
katmel98
Jr. Member
 
Total Posts:  12
Joined:  2011-07-18
 

Hi, as I stated previously in another post, 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 “payment_method_is_active”, the problem is I can’t find this event nowhere. I thought it should be in Mage->Payment->Model->Method-> <somewhere>, but I can’t find it until now.

Could you help me on this?

Thanks in advance.

Melvin

 
Magento Community Magento Community
Magento Community
Magento Community
 
G_Mehta
Guru
 
Avatar
Total Posts:  418
Joined:  2010-01-27
India
 

You find that event inside sales module; open “config.xml” file of sales module.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ensignkid
Jr. Member
 
Total Posts:  4
Joined:  2010-12-11
 
katmel98 - 16 August 2011 12:42 AM

Hi, as I stated previously in another post, 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 “payment_method_is_active”, the problem is I can’t find this event nowhere. I thought it should be in Mage->Payment->Model->Method-> <somewhere>, but I can’t find it until now.

Could you help me on this?

Thanks in advance.

Melvin

For instances like this, download a file search program that will search within hundreds or thousands of files at once for certain words or strings. I use Windows Grep, which is free.

 
Magento Community Magento Community
Magento Community
Magento Community
 
katmel98
Jr. Member
 
Total Posts:  12
Joined:  2011-07-18
 

Thanks for the answer, yes Gaurav I found it inside the config.xml, now what I don’t understand is how the system use it to know what kind of payment method will be available to checkout. Is there any variable that this method needs to be true in order to say some method is active or not?

Thanks in advance.

Melvin

 
Magento Community Magento Community
Magento Community
Magento Community
 
katmel98
Jr. Member
 
Total Posts:  12
Joined:  2011-07-18
 

The problem is that I’ve implemented a payment method and hacking the code I’ve been going down to this piece of code that doesn’t allow my payment method to be seen by checkout page. BUT I’ve say in the options “Yes” to be seen by the customer as payment method. To be honest I’m a little bit annoyed for this.

Please if you can give me a hand on this, is really urgent and I don’t find answers no matter I look for.

Regards,

Melvin

 
Magento Community Magento Community
Magento Community
Magento Community
 
raulsanchez
Sr. Member
 
Avatar
Total Posts:  83
Joined:  2011-02-22
 
katmel98 - 16 August 2011 05:32 AM

Thanks for the answer, yes Gaurav I found it inside the config.xml, now what I don’t understand is how the system use it to know what kind of payment method will be available to checkout. Is there any variable that this method needs to be true in order to say some method is active or not?

Thanks in advance.

Melvin

In the config.xml we see…

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

It means when event is dispatched the method restrictAdminBillingAgreementUsage() from class Mage_Sales_Model_Observer (sales/observer) is called

This method…

/**
     * Block admin ability to use customer billing agreements
     *
     * @param Varien_Event_Observer $observer
     */
    public function restrictAdminBillingAgreementUsage($observer)
    
{
        $methodInstance 
$observer->getEvent()->getMethodInstance();
        if (!(
$methodInstance instanceof Mage_Sales_Model_Payment_Method_Billing_AgreementAbstract)) {
            
return;
        
}
        
if (!Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/use')) {
            $observer
->getEvent()->getResult()->isAvailable false;
        
}
    }

Hope it helps to find your solution…

 
Magento Community Magento Community
Magento Community
Magento Community
 
G_Mehta
Guru
 
Avatar
Total Posts:  418
Joined:  2010-01-27
India
 

If you try to making a payment module; refer this post for Payment Module

I"m not sure how did you make payment module; but through above post you definitely show your payment method into checkout section..

Good Luck. !

 
Magento Community Magento Community
Magento Community
Magento Community
 
katmel98
Jr. Member
 
Total Posts:  12
Joined:  2011-07-18
 

The problem I found is that this code:

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

Seems to filter my payment method, doing a follow to the \\\"payment_method_is_active\\\" it sends to me, like a previous post saids, to a function that checks if my payment method is an instance of \\\"Mage_Sales_Model_Payment_Method_Billing_AgreementAbstract\\\" BUT the other payments methods that are presenting in the checkout payment list are not instance of this class (Cc, CheckMo, i.e.). So I can\\\’t find a reason why it doesn\\\’t show my payment method.

I\\\’m a little bit annoyed with this, any help will be great at this stage.

Cheers,

Melvin

 
Magento Community Magento Community
Magento Community
Magento Community
 
G_Mehta
Guru
 
Avatar
Total Posts:  418
Joined:  2010-01-27
India
 

If you extends your class with “Mage_Payment_Model_Method_Abstract” then you must have to write following line in your class..

Did you done it??

For instance:
protected $_code = ‘checkmo’; //Your payment method code
protected $_formBlockType = ‘payment/form_checkmo’; // Block class of your payment method
protected $_infoBlockType = ‘payment/info_checkmo’; // Not recommended

Refer this Post for more Info

Good Luck.!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
katmel98
Jr. Member
 
Total Posts:  12
Joined:  2011-07-18
 

Yeap, I have the first two lines you say in the class, the \"info\" one is not there.

Melvin

 
Magento Community Magento Community
Magento Community
Magento Community
 
G_Mehta
Guru
 
Avatar
Total Posts:  418
Joined:  2010-01-27
India
 

of fine… also make sure in config.xml file you define the model class
For instance:

<default>
        <
payment>
            <
method name>
                <
model><module name>/<class name></model//Model class name
                
<order_status>processing</order_status>
                <
allowspecific>0</allowspecific>                                                                
            </
method name>
        </
payment>
</default>
 
Magento Community Magento Community
Magento Community
Magento Community
 
katmel98
Jr. Member
 
Total Posts:  12
Joined:  2011-07-18
 

Yep, it exists. I’m a little bit frustrated with it. To be honest I\\\\\\\\\\\\\\\’ve implemented it in my devel environment (standard installation) BUT when I try to install it in the production environment it doesn\\\\\\\\\\\\\\\’t work. The prod env is customized but I take care about put the files where they should be. So, don’t know what else to do.

Maybe, this can be done by a bad configuration or parameter in the Admin area? In the development environment I’m using the standard example database, but in the prod environment we have just subscription products? Can it make the difference? Should I need to configure something in order to allow this new payment method works with the subscription products?

Just ideas,

Thanks Gaurav (and everybody there) for your help and answers.

Regards,

Melvin

 
Magento Community Magento Community
Magento Community
Magento Community
 
G_Mehta
Guru
 
Avatar
Total Posts:  418
Joined:  2010-01-27
India
 

No, i don’t think so it makes any effect with subscription products… may be there is another issue.

 
Magento Community Magento Community
Magento Community
Magento Community
 
katmel98
Jr. Member
 
Total Posts:  12
Joined:  2011-07-18
 

Thanks to all for your help, now I would like to know if someone can explain me, please, what this code means:

if (!Mage::getSingleton(’admin/session’)->isAllowed(’sales/order/actions/use’)) {
$observer->getEvent()->getResult()->isAvailable = false;
}

It seems that this is the piece of code that have my headache wink

Specially, the validation.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagePsycho
Moderator
 
Avatar
Total Posts:  1702
Joined:  2009-06-23
 

FYI,
‘payment_method_is_active’ is an event dispatched my the Magento system which helps us to filter the payment method based on some conditions.
For details about the ‘payment_method_is_active’ implementation, please refer:
http://www.blog.magepsycho.com/how-to-filter-payment-method-in-onepage-checkout

Thanks
Regards

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