【问题标题】:Magento How to add a varchar attribute whit addAttribute specifiying a max lengthMagento 如何使用指定最大长度的 addAttribute 添加 varchar 属性
【发布时间】:2014-06-24 17:16:08
【问题描述】:

我正在使用 magento,我正在尝试添加一个类型为 varchar(50) 的新类别属性。我添加了新属性:

$installer->addAttribute('catalog_category', 'shortdesc', array(
                    'type'              => 'varchar',
                    'backend'           => '',
                    'frontend'          => '',
                    'label'             => 'Descripción Corta',
                    'input'             => 'textarea',
                    'class'             => '',
                    'source'            => '',
                    'global'            => 1,
                    'visible'           => 1,
                    'required'          => 0,
                    'user_defined'      => 0,
                    'default'           => '',
                    'searchable'        => 0,
                    'filterable'        => 0,
                    'comparable'        => 0,
                    'visible_on_front'  => 0,
                    'unique'            => 0,
                    'position'          => 1,
                ));

但最大长度为 255。如何将属性长度更改为 50?

【问题讨论】:

  • 我认为你不能使用 magento 风格来做到这一点,但我认为你可以使用 java-script 或 jquery 使用属性 id 来做到这一点

标签: magento attributes varchar string-length


【解决方案1】:

确实,Magento 对 255 值进行了硬编码(从 Community Edition 1.8.1.0 开始)并且不接受替换它的参数。

这对您来说应该不是问题,因为 VARCHAR(255) 是可以存储的最大字符数,但是如果您存储的空间少于它所需要的空间,它不会占用更多的空间。如果你真的需要一个硬限制,你总是可以添加代码来观察类别的保存前事件并在那里删除你的字符串。

或者,在极端情况下,您真的想要对数据库进行此硬限制,您可以alter the table and modify the column

【讨论】:

    猜你喜欢
    • 2023-01-20
    • 1970-01-01
    • 2011-11-12
    • 2011-12-17
    • 2012-02-08
    • 2016-09-14
    • 1970-01-01
    • 2011-02-14
    相关资源
    最近更新 更多