无法在Magento上保存multiselect属性 [英] Can't save multiselect attribute on Magento

查看:48
本文介绍了无法在Magento上保存multiselect属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过安装程序创建了一个自定义的多选产品属性.如果我仅从多选值中选择一个选项,它就可以工作并且可以保存产品.但是,如果我选择2个值,则该产品仍然可以保存,但又重新选择了1个选择的值.简而言之,我无法保存带有2个选定值的属性.

I created a custom multiselect product attribute through installer. It works and I can save the product if I only select one option from the multiselect values. But if I select 2 values, the product still can be saved but came back up with 1 selected value again. In short, I can't save the attribute with 2 selected values.

$installer = $this;
$installer->startSetup();

$installer->addAttribute('catalog_product', 'attr_id',array(
         'label'             => 'Frontend Name',
         'type'              => 'int',
         'input'             => 'multiselect',
         'backend'           => 'eav/entity_attribute_backend_array',
         'frontend'          => '',
         'source'            => '',
         'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
         'visible'           => true,
         'required'          => false,
         'user_defined'      => true,
         'searchable'        => false,
         'filterable'        => false,
         'comparable'        => false,
         'option'            => array (
            'value' => array(
                     '0' => array('First Option'),
                     '1' => array('Second Option'),
                     '2' => array('Third Option'),
                     )
                    ),
         'visible_on_front'  => false,
         'visible_in_advanced_search' => false,
         'unique'            => false
));

$installer->endSetup();

推荐答案

问题出在您的属性类型上.

The problem comes from the type of your attribute.

'type'=> 'int',

保存来自multiselect属性的值,并用逗号 1、4、6 串联起来.为此,您需要将属性设置为 varchar text .如果您不打算为该属性提供数百个选项,则建议使用 varchar .
现在配置方式,保存时将值 1,4,6 转换为int,最终结果为 1 .

The values from multiselect attributes are saved concatenated by comma 1,4,6. For this you need the attribute to be varchar or text. I recommend varchar if you are not going to have hundreds of options for the attribute.
The way is configured now, when it's saved, the value 1,4,6 is converted to int and it ends up being 1.

这篇关于无法在Magento上保存multiselect属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆