Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

zend framework - Magento module Fatal error: Class 'Mage_Cashondelivery_Helper_Data' not found in xampphtdocsmagentoappMage.php on line 516

I am developing a payment Module for Magento. I did this using this tutorial

http://www.magentocommerce.com/wiki/5_-_modules_and_development/payment/create-payment-method-module

I have created folder

app/local/Companyname/Cashondelivery/Block
app/local/Companyname/Cashondelivery/Model
app/local/Companyname/Cashondelivery/controller
app/local/Companyname/Cashondelivery/etc
app/local/Companyname/Cashondelivery/helpers

The etc/config.xml

    <?xml version="1.0"?>
    <config>
        <modules>
           <Companyname_Cashondelivery>
    <!-- declare module's version information for database updates -->
              <version>0.1.0</version>
           </Companyname_Cashondelivery>
        </modules>

        <global>


    <!-- declare model group for new module -->
            <models>
    <!-- model group alias to be used in Mage::getModel('newmodule/...') -->
                <createorder>
    <!-- base class name for the model group -->
                    <class>Companyname_Cashondelivery_createorder</class>
                </createorder>
            </models>

    <!-- declare resource setup for new module -->
            <resources>
    <!-- resource identifier -->
                <cashondelivery_setup>
    <!-- specify that this resource is a setup resource and used for upgrades -->
                    <setup>
    <!-- which module to look for install/upgrade files in -->
                        <module>Companyname_Cashondelivery</module>
                    </setup>
    <!-- specify database connection for this resource -->
                    <connection>
    <!-- do not create new connection, use predefined core setup connection -->
                        <use>core_setup</use>
                    </connection>
                </cashondelivery_setup>
                <cashondelivery_write>
                    <connection>
                      <use>core_write</use>
                    </connection>
                </cashondelivery_write>
                <cashondelivery_read>
                   <connection>
                    <use>core_read</use>
                  </connection>
                </cashondelivery_read>
            </resources>
        </global>

    <!-- declare default configuration values for this module -->
        <default>
    <!-- 'payment' configuration section (tab) -->
            <payment>
    <!-- 'newmodule' configuration group (fieldset) -->
                <cashondelivery>
    <!-- by default this payment method is inactive -->
                    <active>0</active>
    <!-- model to handle logic for this payment method -->
                    <model>cashondelivery/createorder</model>
    <!-- order status for new orders paid by this payment method -->
                    <order_status>pending</order_status>
    <!-- default title for payment checkout page and order view page -->
                    <title>Companyname</title>                
                </cashondelivery>
             </payment>
        </default>
</config>

The app/local/Companyname/Modulename/etc/system.xml

<?xml version="1.0"?>
<config>
   <sections>
        <payment>
            <groups>
                <cashondelivery translate="label" module="cashondelivery">
                    <label>Cash On Delivery</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>10</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <!--<comment>[CDATA[<a href="http://celinks.magento.com/authorize_netRegistration" target="_blank">Click here to sign up for an Authorize.net account</a>]]></comment>-->
                    <fields>
                        <active translate="label">
                            <label>Enabled</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </active>
                        <email_customer translate="label">
                            <label>Email Customer</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>10</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </email_customer>
                        <login translate="label">
                            <label>API Login ID</label>
                            <frontend_type>obscure</frontend_type>
                            <backend_model>adminhtml/system_config_backend_encrypted</backend_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>
                        </login>

                        <merchant_email translate="label">
                            <label>Merchant's Email</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>11</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </merchant_email>
                        <order_status translate="label">
                            <label>New Order Status</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_order_status_processing</source_model>
                            <sort_order>4</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </order_status>
                        <sort_order translate="label">
                            <label>Sort Order</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>100</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </sort_order>
                        <test translate="label">
                            <label>Test Mode</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>5</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </test>
                        <debug translate="label">
                            <label>Debug</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>6</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </debug>
                        <title translate="label">
                            <label>Title</label>
                            <frontend_type>text</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>
                        </title>

                        <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>
                        <cgi_url>
                            <label>Gateway URL</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>5</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </cgi_url>                        
                        <min_order_total translate="label">
                            <label>Minimum Order Total</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>98</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...