Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.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
Php Magento:使用选项创建新属性_Php_Magento - Fatal编程技术网

Php Magento:使用选项创建新属性

Php Magento:使用选项创建新属性,php,magento,Php,Magento,我正在为属性创建一个简单的导入脚本,但我不知道如何向属性添加选项。“attribute”的每个属性都是直接的,除了添加一个选项。这是在创建属性时可以完成的吗 我使用的代码基本上如下 $model = Mage::getModel('catalog/resource_eav_attribute'); $data = array( 'is_global' => '0', 'frontend_input'

我正在为属性创建一个简单的导入脚本,但我不知道如何向属性添加选项。“attribute”的每个属性都是直接的,除了添加一个选项。这是在创建属性时可以完成的吗

我使用的代码基本上如下

$model = Mage::getModel('catalog/resource_eav_attribute');  
$data = array(
    'is_global'                     => '0',
    'frontend_input'                => 'text',
    'default_value_text'            => '',
    'default_value_yesno'           => '0',
    'default_value_date'            => '',
    'default_value_textarea'        => '',
    'is_unique'                     => '0',
    'is_required'                   => '0',
    'frontend_class'                => '',
    'is_searchable'                 => '1',
    'is_visible_in_advanced_search' => '1',
    'is_comparable'                 => '1',
    'is_used_for_promo_rules'       => '0',
    'is_html_allowed_on_front'      => '1',
    'is_visible_on_front'           => '0',
    'used_in_product_listing'       => '0',
    'used_for_sort_by'              => '0',
    'is_configurable'               => '0',
    'is_filterable'                 => '0',
    'is_filterable_in_search'       => '0',
    'backend_type'                  => 'varchar',
    'default_value'                 => '',
    'frontend_label'                => '',
    'attribute_code'                => ''
);  
foreach ($header as $key => $value){
    if(isset($data[$key]) !== false){
        $data[$key] = $row[$header[$key]];
    }
}

$data['option'] = ?WHAT DO I DO HERE¿

$model->addData($data); 
$model->setEntityTypeId(Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId());

$model->setIsUserDefined(1);
$model->save();
}

编辑:

感谢马尔科的例子,我尝试了以下方法:

$data['option'] = array (
        'value' => array(
                'wood' => array('Wood'),
                'metal' => array('Metal')
        )
);
一般来说,他添加属性的方法略有不同,但该属性的值工作原理相同

W00t

您可以创建sql脚本(教程:)并在内部放入类似以下内容的内容:

$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();

$setup->addAttribute('catalog_product', 'attr_code', array(
    'group'         => 'General',
    'input'         => 'select',
    'type'          => 'text',
    'label'         => 'Material',
    'backend'       => '',
    'visible'       => 1,
    'required'      => 0,
    'user_defined' => 1,
    'searchable' => 1,
    'filterable' => 0,
    'comparable'    => 1,
    'visible_on_front' => 1,
    'source' => 'eav/entity_attribute_source_table',
    'visible_in_advanced_search'  => 0,
    'is_html_allowed_on_front' => 0,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'configurable' => 1,
    'option'  => array (
            'value' => array(
                    'wood' => array('Wood'),
                    'metal' => array('Metal')
            )
    ),
));

$installer->endSetup();

这将使用木材和金属选项创建属性材质

我正在编写CLI脚本,$this变量是什么上下文?$this变量实际上是digram\u Productvariants\u Model\u Resource\u Mysql4\u设置类的实例。艾伦·斯托姆在我上面发布的教程中对此进行了解释。