Unable to get basic custom Magento payment module to work
I want to create a payment module which is basically identical to the Check/Money Order method, in that when you click the radio button to select it, a bit of information with instructions appears underneath.
I have created a module which works, but I can't get that info to appear underneath. When I enable it, I simply get a blank error page (with no message).
I have the following files inside my module folder:
- Block/Form/Bacs.php
- Block/Info/Bacs.php
- etc/config.xml
- etc/system.xml
- Model/Method/Bacs.php
And frontend-wise I have the following files:
- payment/info/bacs.phtml
- payment/form/bacs.phtml
I think the problem lies in my block php files because when I remove the links to them from my Model file the module works. Here's an overview of the files where I think the problem lies:
Model/Method/Bacs.php
class Creare_Bacs_Mod开发者_如何学Goel_Method_Bacs extends Mage_Payment_Model_Method_Abstract
{
protected $_code = 'bacs';
protected $_formBlockType = 'bacs/form_bacs';
protected $_infoBlockType = 'bacs/info_bacs';
public function assignData($data)
{
$details = array();
if ($this->getInstructions()) {
$details['instructions'] = $this->getInstructions();
}
if (!empty($details)) {
$this->getInfoInstance()->setAdditionalData(serialize($details));
}
return $this;
}
public function getInstructions()
{
return $this->getConfigData('instructions');
}
}
Block/Info/Bacs.php
class Creare_Bacs_Block_Info_Bacs extends Mage_Payment_Block_Info
{
protected $_instructions;
protected function _construct()
{
parent::_construct();
$this->setTemplate('payment/info/bacs.phtml');
}
public function getInstructions()
{
if (is_null($this->_instructions)) {
$this->_convertAdditionalData();
}
return $this->_instructions;
}
protected function _convertAdditionalData()
{
$details = @unserialize($this->getInfo()->getAdditionalData());
if (is_array($details)) {
$this->_instructions = isset($details['instructions']) ? (string) $details['instructions'] : '';
} else {
$this->_instructions = '';
}
return $this;
}
}
Block/Form/Bacs.php
class Creare_Bacs_Block_Form_Bacs extends Mage_Payment_Block_Form
{
protected function _construct()
{
parent::_construct();
$this->setTemplate('payment/form/bacs.phtml');
}
}
Within my system.xml file I have this which brings out the instructions textarea in the picture below:
<instructions translate="label">
<label>Instructions</label>
<frontend_type>textarea</frontend_type>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</instructions>
Really not sure what I've done wrong. I don't want this first post to be too long so let me know if any more files are needed. I'm sure that the problem is within the block files I have provided.
Can anyone tell me if I have made an error in creating any of the files I have shown above?
I'm such a dummy. Forgot to register blocks in config.xml (you would have spotted it Anton S)
<blocks>
<bacs>
<class>Creare_Bacs_Block</class>
</bacs>
</blocks>
精彩评论