1

我刚刚完成了我的一种自定义运输方法,它在主要方法中有多种方法。所以我想让“允许的方法”列表显示在管理部分。所以我在我的 system.xml 中得到了下面的块

 <allowed_methods translate="label">
    <label>Allowed Methods</label>
    <frontend_type>multiselect</frontend_type>
    <source_model>mycompany_shipping/carrier_somefolder_definitions_methods</source_model>
    <sort_order>20</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>0</show_in_store>
    <can_be_empty>1</can_be_empty>
 </allowed_methods>

但是 Magento 找不到我的课程,因为它总是在“法师”而不是“本地”中查找,它只是抛出这个错误,

include(Mage/Mycompany/Shipping/Model/Carrier/Somefolder/Definitions/Methods.php): 
failed to open stream: No such file or directory  in /Development/trunk/lib/Varien/Autoload.php on line 93

但是我的班级在local/Mycompany/Shipping/Model/Carrier/Somefolder/Definitions/Methods.php,班级名称是Mycompany_Shipping_Model_Carrier_Somefolder_Definitions_Methods

我想可能是我在我的 config.xml 中遗漏了一些东西,所以这是我的 config.xml

<global>
    <models>
        <mycompshipping>
            <class>Mycompany_Shipping_Model</class>
        </mycompshipping>
    </models>
    <resources>
        <mycompshipping_setup>
            <setup>
                <module>Mycompany_Shipping</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </mycompshipping_setup>
    </resources>
</global>
<default>
    <carriers>
        <mycompanyrate>
            <model>Mycompany_Shipping_Model_Carrier_Mycompanyrate</model>
        </mycompanyrate>
    </carriers>
</default>

任何想法为什么 Magento 找不到我的课程?

4

1 回答 1

3

如果 Magento 预先Mage添加到您的课程中,这几乎总是意味着您的配置有误。

查看您提供的信息,您的源模型配置为

mycompany_shipping/carrier_somefolder_definitions_methods

那是 的组名mycompany_shipping和 的类名carrier_somefolder_definitions_methods。这意味着 Magento 将通过调用来实例化您的源模型

Mage::getModel('mycompany_shipping/carrier_somefolder_definitions_methods');

然而,看着你的config.xml

<models>
    <mycompshipping>
        <class>Mycompany_Shipping_Model</class>
    </mycompshipping>
</models>

您已将模块配置为“声明”模型组名称mycompshipping。这意味着当您实例化模块的类时,您使用的形式

//instantiates as `Mycompany_Shipping_Model_Carrier_Mycompanyrate`
Mage::getModel('mycompshipping/carrier_mycompanyrate');

您需要更正您system.xml以实例化正确的源模型,或更改config.xml以公开正确的组名。

于 2013-11-06T23:49:02.600 回答