首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建Magento后端字段ReadOnly

创建Magento后端字段ReadOnly
EN

Stack Overflow用户
提问于 2013-05-14 03:10:29
回答 3查看 3.8K关注 0票数 3

我想在客户端的Magento的后端创建一个只读字段。创建要知道的字段(通过模块)如下所示:

代码语言:javascript
复制
 $installer->addAttribute("customer", "attrcode",  array(
     "type"     => "varchar",
     "backend"  => "",
     "label"    => "label",
     "input"    => "text",
     "source"   => "",
     "visible"  => true,
     "required" => false,
     "default" => "",
     "frontend" => "",
     "unique"     => false,

    ));

这样它就产生了场,但他不仅仅是在读...

谢谢

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-05-14 07:45:27

一种可能的解决方案是使用javascript禁用页面加载时的按钮。

创建一个js文件并将其上传到管理皮肤/js目录(disable_button.js)

添加

代码语言:javascript
复制
document.observe('dom:loaded', function(){
     $("target_input_id").disabled=true;
});

然后添加或更新您的local.xml以包含js文件

代码语言:javascript
复制
<?xml version="1.0"?>
<layout version="0.1.0">
    <adminhtml_customer_edit>
        <reference name="head">
            <action method="addItem"><type>skin_js</type><script>js/disable_button.js</script></action>
        </reference>
    </adminhtml_customer_edit>
</layout>
票数 3
EN

Stack Overflow用户

发布于 2013-05-14 07:34:09

我认为使用addAttribute()是不可能的,_prepareValues($attr)方法只允许存储在$data中的特定值。

查看@ app/code/core/Mage/Eav/Model/Entity/Setup.php

代码语言:javascript
复制
public function addAttribute($entityTypeId, $code, array $attr)
{
    $entityTypeId = $this->getEntityTypeId($entityTypeId);
    $data = array_merge(
        array(
            'entity_type_id' => $entityTypeId,
            'attribute_code' => $code
        ),
        $this->_prepareValues($attr);
     );
    .....
    if ($attributeId) {
        $this->updateAttribute($entityTypeId, $attributeId, $data, null, $sortOrder);
    } else {
        $this->_insertAttribute($data);
    }
    .......
 }


protected function _prepareValues($attr)
{
    $data = array(
        'backend_model'   => $this->_getValue($attr, 'backend'),
        'backend_type'    => $this->_getValue($attr, 'type', 'varchar'),
        'backend_table'   => $this->_getValue($attr, 'table'),
        'frontend_model'  => $this->_getValue($attr, 'frontend'),
        'frontend_input'  => $this->_getValue($attr, 'input', 'text'),
        'frontend_label'  => $this->_getValue($attr, 'label'),
        'frontend_class'  => $this->_getValue($attr, 'frontend_class'),
        'source_model'    => $this->_getValue($attr, 'source'),
        'is_required'     => $this->_getValue($attr, 'required', 1),
        'is_user_defined' => $this->_getValue($attr, 'user_defined', 0),
        'default_value'   => $this->_getValue($attr, 'default'),
        'is_unique'       => $this->_getValue($attr, 'unique', 0),
        'note'            => $this->_getValue($attr, 'note'),
        'is_global'       => $this->_getValue($attr, 'global',
                                 Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
                             ),
    );

    return $data;
}
票数 1
EN

Stack Overflow用户

发布于 2015-08-21 18:12:39

我已经开发了这样的扩展,为产品,类别和CMS页面工作。您只需定义一些规则并选择要显示为只读的属性。

扩展地址:https://www.bubbleshop.net/magento-admin-readonly.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16529412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档