5

I get fatal error while setting up custom payment method block for checkout page

`Fatal error: Call to a member function setMethod() on a non-object in 
app/code/core/Mage/Payment/Helper/Data.php on line 106` 

Here's my Implementation

Payment Method File paths

app/code/local/SecurePay/SecureFrame/Block/Form
app/code/local/SecurePay/SecureFrame/controllers
app/code/local/SecurePay/SecureFrame/Model/Standard.php

Block Class

<?php
     // app/code/local/SecurePay/SecureFrame/Block/Form/SecureFrame.php
class SecurePay_SecureFrame_Block_Form_SecureFrame extends Mage_Payment_Block_Form
{
 protected function _construct()
  {
    parent::_construct();
    $this->setTemplate('secureframe/form/secureframe.phtml');
  }
}

Payment Model

<?php
class SecurePay_SecureFrame_Model_Standard extends Mage_Payment_Model_Method_Abstract {
    protected $_code = 'secureframe'; 
    protected $_formBlockType = 'secureframe/form_secureframe'; //This line thows the error
// other stuff ....
}

Also If I comment the line protected $_code = 'secureframe'; Error disappears but obviously custom payment block does not get set

Edit:
Config.xml File

    <?xml version="1.0"?>
<config>
  <modules>
    <SecurePay_SecureFrame>
      <version>0.1.0</version>
    </SecurePay_SecureFrame>
  </modules>
  <global>
    <models>
      <secureframe>
        <class>SecurePay_SecureFrame_Model</class>
      </secureframe>
    </models>
    <helpers>
      <secureframe>
        <class>SecurePay_SecureFrame_Helper</class>
      </secureframe>
    </helpers>
    <blocks>
      <secureframe>
        <class>SecurePay_SecureFrame_Block</class>
      </secureframe>
    </blocks>
  </global>
  <default>
    <payment>
      <secureframe>
        <model>secureframe/standard</model>
        <active>0</active>
        <order_status>pending</order_status>
        <title>Payment via Securepay</title>
        <payment_action>sale</payment_action>
        <test_mode>1</test_mode>
        <merchant_id></merchant_id>

        <allowspecific>0</allowspecific>

        <currency_accepted>AUD</currency_accepted>
        <sort_order>1</sort_order>
      </secureframe>
    </payment>
  </default>
  <frontend>
    <routers>
      <secureframe>
        <use>standard</use>
        <args>
          <module>SecurePay_SecureFrame</module>
          <frontName>SECUREPAY</frontName>
        </args>
      </secureframe>
    </routers>
  </frontend>
</config>

Template file path for phtml file in template directory

app/design/frontend/base/default/template/securepay/secureframe/form/secureframe.phtml

What I am doing wrong ?? How to resolve this error and display custom form on checkout page

P.S. Also tried placing the form phtml file outside the securepay directory like

app/design/frontend/base/default/template/secureframe/form/secureframe.phtml

However error does not get resolved

Edit Here is the code from Helper file which is giving error

 public function getMethodFormBlock(Mage_Payment_Model_Method_Abstract $method)
{
    $block = false;
    $blockType = $method->getFormBlockType();
    if ($this->getLayout()) {
        $block = $this->getLayout()->createBlock($blockType); // This might be causing error, not sure (from helper file reported in error)

        $block->setMethod($method);
    }
    return $block;
}
  • can you please add your module etc/config.xml file in comment? – Abdul Oct 31 '15 at 5:22
  • Added config.xml file – echoashu Nov 2 '15 at 19:58
2

When you use a second upper letter in your files and class, things change a litte:

The Block Type Schema: ModuleName/ClassPath:

ModuleName: lowercase when a single name and use exactly the same string when has more than one uppercase letter on name.

ClassPath: lowercase when there is a single name or use first letter on lowercase and in all other first letters use uppercase.

So if your block class is: SecurePay_SecureFrame_Block_Form_SecureFrame Change your block type to:

protected $_formBlockType = 'SecureFrame/form_secureFrame';
  • It's interesting to see two approaches from different angles. @Abdul's answer above also recognised that the class name didn't match the $_formBlockType, but whereas you suggest changing $_formBlockType he suggests changing the Block class itself. Though I think he forgot that as well as changing the block class name you have to also change the filename to match. – Doug McLean Nov 20 '15 at 16:34
  • Yes. Abdul's approaches just will work if you change the name of module too, from SecureFrame to Secureframe, like this: SecurePay_Secureframe_Block_Form_Secureframe. He forgot the ModuleName. – Denis Spalenza Nov 20 '15 at 16:39
  • My approach is based in your initial situation. Class: SecurePay_SecureFrame_Block_Form_SecureFrame. Filepath: app/code/local/SecurePay/SecureFrame/Block/Form/SecureFrame.php – Denis Spalenza Nov 20 '15 at 16:43
  • Let me know after you try my approach. – Denis Spalenza Nov 20 '15 at 16:44
  • +1 for details about Block Type Schema: ModuleName/ClassPath: However evn changing the $_formBlockType giving the same fatal error I hav updated the question with snippet from core file, that might be useful – echoashu Nov 20 '15 at 22:13
1

Please change code from

<?php
     // app/code/local/SecurePay/SecureFrame/Block/Form/SecureFrame.php
class SecurePay_SecureFrame_Block_Form_SecureFrame extends Mage_Payment_Block_Form
{
 protected function _construct()
  {
    parent::_construct();
    $this->setTemplate('secureframe/form/secureframe.phtml');
  }
}

TO

<?php
     // app/code/local/SecurePay/SecureFrame/Block/Form/SecureFrame.php
class SecurePay_SecureFrame_Block_Form_Secureframe extends Mage_Payment_Block_Form
{
    protected function _construct()
    {
        parent::_construct();
        $this->setTemplate('secureframe/form/secureframe.phtml');
    }
}
  • Applied. Could not get the error resolved with this change in class name. Also, I am working on displaying custom payment form, and info block is separate thing which appears on right sidebar. Correct me if I'm wrong Thanks – echoashu Nov 2 '15 at 19:59
  • can you please vote me if you are satisfaction with my ans? – Abdul Nov 3 '15 at 4:24
  • sure, however you are suggesting to change the classname to Block_Info, but i'm stucked in implementing payment form which appears while choosing the payment method Could you please help me resolve the error as why that is givig me invalid block type fatal error ?? Thanks :-) – echoashu Nov 3 '15 at 4:37
  • i am updated my ans please see and replace code – Abdul Nov 3 '15 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.