2016-01-20 20 views
1

我通过更新SQL脚本,这样增加属性安装脚本(sql脚本),无法理解Magento的

$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', 

回答

1

我不能在您的文章发表评论。尝试了解您是否从某处复制了此代码。从你的代码,我知道你想添加一个“客户地址属性”命名为“customer_address”

“源” =>“address_group/address_attribute_source_group”

上述言下之意是路径。你应该有如下的文件夹/文件路径:

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

Group.php: 类Address_Group_Model_Address_Attribute_Source_Group ...

因为,这个属性的类型的=>“选择”,你应该有这个文件中的选项数组“Group.php”

选项阵应该是非常相似的:

public function toOptionsArray() { 

    return array(
     array(
      'label' => '', 
      'value' => '' 
     ), 
     array(
      'label' => Yes, 
      'value' => 1 
     ), 
     array(
      'label' => No, 
      'value' => 0 
     ) 
    ); 
} 

让我知道如果你得到它!

乐意帮忙!

编码快乐......

+0

我把它给我的意见,但我的阶级是这样的,“类Address_Group_Model_Address_Attribute_Source_Group 扩展Mage_Eav_Model_Entity_Attribute_Source_Table { }” –

+0

和“** Mage_Eav_Model_Entity_Attribute_Source_Table **'没有任何东西像** toOptionsArray()** –

+0

你将不得不在Group.php中创建这个函数,你的值就是这个。 – Shivani

1

它指向为属性提供选项的类。由于属性使用select输入,它需要提供选项。通过调用Mage::getModel()并将源的值传递给它来创建此类。要找到该类,您需要找到可用模块的​​3210文件中的节点models/address_group。这将提供类前缀。接下来会在该前缀后添加斜杠以创建类名称。所以在这种情况下,它会解决类似Company_AddressGroupModule_Model_Address_Attribute_Source_Group。这个类需要实现toOptionsArray方法,在下面的格式返回一个数组:

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

我得到了它,可以看到波纹管 –