The reason your module needs a helper class is the module
argument in the system.xml file:
<cashondelivery translate="label" module="cashondelivery">
Magento passes the module
argument to the Mage::helper()
factory method. This in turn completes the class id to cashondelivery/data
.
Mage::helper('cashondelivery');
// identical to Mage::helper('cashondelivery/data');
Now Magento checks for the class prefix to use by looking for the node global/helpers/cashondelivery/class
which is missing.
Rather straightforward so far, but here is where it might be a little confusing for some.
If Magento doesn't find a helper class prefix, it tries to makes one up by prefixing the class id with mage_
and appending _helper
.
So this gives you mage_cashondelivery_helper
as the class prefix, and mage_cashondelivery_helper_data
as the full class name.
The autoloader turns this into Mage/Cashondelivery/Helper/Data.php, which can't be found, and hence the exception you are experiencing.
Besides creating the Companyname_Cashondelivery_Helper_Data
class, you need to add the class group mapping to your config.xml file as follows:
<global>
<helpers>
<cashondelivery>
<class>Companyname_Cashondelivery_Helper</class>
</cashondelivery>
</helpers>
</global>
This class group to class prefix mapping is all you are missing.
In your system.xml you have the following code
<payment_action translate="label">
<label>Payment Action</label>
<frontend_type>select</frontend_type>
<source_model>cashondelivery/createorder</source_model>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</payment_action>
The source model is specified as cashondelivery/createorder
.
According to the code you posted in the question you reference, this class is a payment method model, not a source model.
If you implement the toOptionArray()
method on the model it would work as a system config source model as well, but that doesn't seem like a bad choice.
I would guess the source model you are looking for is something like paygate/authorizenet_source_paymentAction
.
Background
Source models in Magento exist to provide option lists to select and multiselects. For this purpose they implement the toOptionArray()
method.
The options are returned as an array that has the following format:
public function toOptionArray()
{
return array(
array('value' => $value1, 'label' => 'The label for option 1'),
array('value' => $value2, 'label' => 'The label for option 2'),
array('value' => $value3, 'label' => 'The label for option 3')
// ... etc ...
);
}
System configuration source models don't need to extend super class and don't need to implement any methods besides toOptionArray()
.
EAV select and multiselect attributes also make use of source models, but those need to extend eav/entity_attribute_source_abstract
and are more complex, so I'll won't go into more details at this place.
Best Answer
You could check to see if you have Compiler enabled under System>Tools>Compiler. If it is enabled, disable it and then flush the Magento Cache. There after you may no longer get this error, as this is what worked for me.
You can always Enable the Compiler again afterwards.