【问题标题】:Adding a Custom Backend Model to a Custom Attribute将自定义后端模型添加到自定义属性
【发布时间】:2012-02-13 10:09:56
【问题描述】:

我正在尝试为自定义属性设置自定义后端模型。问题是 Magento 将 'Mage' 目录添加到路径中,所以我不能将所有文件都保留在我的扩展目录中。

代码:

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('catalog_category', $postData['attribute_code'], array(
                        'label'      => $postData['frontend_label'],
                        'input'      => $postData['frontend_input'],
                        'backend'    => 'my_company/myextension_model_category_attribute_backend_file',
                        'required'   => $postData['is_required'],
                        'global'     => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
                        'group'      => $postData['attribute_group_name'],
                        'sort_order' => $postData['sort_order']
));

'Mage' 不是相对于我的扩展名的路径,而是前置并导致此错误:

Warning: include(Mage/My_Company/Model/My_Extension/Model/Category/Attribute/Backend/File.php): failed to open stream

我还没有找到适用于 addAttribute() 方法的解决方案。

在疑难解答中,Magento 在哪里添加路径并不清楚。

一切都渲染得很好(我使用的是文件渲染器),但是如果没有后端,它当然不能正确保存。

我正在使用 Magento 1.6.1。

【问题讨论】:

    标签: magento


    【解决方案1】:

    仔细检查您的 app/code/local/Your_Company/Your_Extension/etc/config.xml 是否将您的模型注册到 Magento 系统:

    <global>
        ...
        <models>
            <my_company>
                <class>Company_Extension_Model_Category_Attribute_Backend_File</class>
            </my_company>
        </models>
        ...
    </global>
    

    【讨论】:

    • 关闭,似乎我的语法已关闭。更改我的配置,然后将我的后端更改为“company/category_attribute_backend_file”,导致路径“Company/Extension/Model/Category/Attribute/Backend/File/Category/Attribute/Backend/File.php”的打开流警告失败
    • 好的,将后端设置为“扩展/文件”有效。我也必须更新我的班级名称/路径。谢谢先生。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-01
    • 2020-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-23
    相关资源
    最近更新 更多