Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法理解Magento中的安装脚本(sql脚本)_Magento_Attributes_Sql Update - Fatal编程技术网

无法理解Magento中的安装脚本(sql脚本)

无法理解Magento中的安装脚本(sql脚本),magento,attributes,sql-update,Magento,Attributes,Sql Update,我通过更新sql脚本添加属性,如下所示 $installer = $this; $installer->startSetup(); $installer->addAttribute('customer_address', 'group_id', array( 'label' => 'Address group', 'visible' => true, 'required' => false, 'type' =>

我通过更新sql脚本添加属性,如下所示

$installer = $this;
$installer->startSetup();
$installer->addAttribute('customer_address', 'group_id', array(
'label'        => 'Address group',
'visible'      => true,
'required'     => false,
'type'         => 'int',
'input' => 'select',
'source' => 'address_group/address_attribute_source_group',
'user_defined' => 1,
'position'  => 100
));

.
.
.
$installer->endSetup();
我无法理解下面这句话的意思,我找不到任何解释

'source' => 'address_group/address_attribute_source_group',

它指向为属性提供选项的类。当属性使用
选择
输入时,需要提供选项。这个类是通过调用
Mage::getModel()
并将source的值传递给它来创建的。要查找类,您需要在可用模块的
config.xml
文件中查找节点
models/address\u group
。这将提供类前缀。接下来,斜杠后面的内容被添加到前缀中,以便创建类名。因此,在本例中,它将解析为类似于
公司\地址组模块\模型\地址\属性\源\组
。此类需要实现返回以下格式数组的
toOptionsArray
方法:

array(
    array('value' =>  'option_value', 'label' => 'option_label'),
    ...
);

我无法对你的帖子发表评论。试图了解您是否从某处复制了此代码。从您的代码中,我了解到您想要添加一个名为“Customer\u Address”的“Customer Address属性”

“源”=>“地址\组/地址\属性\源\组”

以上的含义就是路径。您应该有一个文件夹/文件路径,如下所示:

/app/code/local/Address/Group/Model/Address/Attribute/Source/Group.php

Group.php: 类地址\组\模型\地址\属性\源\组

由于该属性的类型为=>“SELECT”,因此您应该在该文件“Group.php”中拥有options数组

选项数组应该非常类似于:

public function toOptionsArray() {
    
    return array(
        array(
            'label' => '',
            'value' => ''
        ),
        array(
            'label' => Yes,
            'value' => 1
        ),
        array(
            'label' => No,
            'value' => 0
        )
    );
}
如果你拿到了就告诉我

很乐意帮忙


愉快的编码…

我知道了,但我的类是这样的,'class Address\u Group\u Model\u Address\u Attribute\u Source\u Group扩展了Mage\u Eav\u Model\u Entity\u Attribute\u Source\u Table{}'和'Mage\u Eav\u Model\u Entity\u Attribute\u Source\u Table'没有类似于tooptionsaray()的内容您必须在Group.php中使用其中的值创建此函数。因为
Mage\u Eav\u Model\u Entity\u Attribute\u Source\u Table
使用数据库表,其中保存了管理员在属性配置表单中添加的所有选项。它使用
getAllOptions
获取它们。同意Zefiryn。。您可以选择使用XML添加与默认magento类似的值。但是,不要直接更新核心文件。我得到了它,可以看到下面给出的我的评论