Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.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/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
Php Magento获取属性类型(例如下拉列表或文本)_Php_Magento - Fatal编程技术网

Php Magento获取属性类型(例如下拉列表或文本)

Php Magento获取属性类型(例如下拉列表或文本),php,magento,Php,Magento,我想知道如何获取产品属性对象的类型。在magento后端,需要在各种选项之间进行选择,如“文本字段”或“下拉” 我正在使用一个产品导入脚本,知道正确设置值的属性类型很重要 有一个简单的魔法方法来获取对象的值: $attribute = Mage::getModel('eav/entity_attribute')->load( $your_attribute_id ); $attribute->getFrontendInput(); 结果是一个短字符串,例如“text”或“selec

我想知道如何获取产品属性对象的类型。在magento后端,需要在各种选项之间进行选择,如“文本字段”或“下拉”


我正在使用一个产品导入脚本,知道正确设置值的属性类型很重要

有一个简单的魔法方法来获取对象的值:

$attribute = Mage::getModel('eav/entity_attribute')->load( $your_attribute_id );
$attribute->getFrontendInput();
结果是一个短字符串,例如“text”或“select”。以下是Magento 1.7(德语翻译)中所有类型的简短列表:

  • 文本:Einzeiliges Textfeld
  • textarea:Mehrzeiliger textbreich
  • 日期:基准
  • 布尔值:Ja/Nein
  • 多选:Mehrfach Auswah
  • select:selected=“selected:下拉列表
  • 价格:Preis
  • 媒体图片:《图片报》
  • weee:Feste Produktsteuer(FPT)
如果需要单个属性中所有选项的列表,请执行以下操作:

Mage::getModel( 'eav/config' )->getAttribute( 'catalog_product' , 'code_of_attribute' )
因此,您已经加载了属性对象。加载对象的其他方法对我不起作用(例如,
Mage::getModel('eav/entity_attribute')->load('xy');

然后使用getSource()方法和getAllOptions方法接收包含所有选项的数组:

$your_attribute->getSource()->getAllOptions(true, true)
结果如下所示:

array(4) {
  [0]=>
  array(2) {
    ["label"]=>
    string(0) ""
    ["value"]=>
    string(0) ""
  }
  [1]=>
  array(2) {
    ["value"]=>
    string(1) "5"
    ["label"]=>
    string(6) "red"
  }
  [2]=>
  array(2) {
    ["value"]=>
    string(1) "4"
    ["label"]=>
    string(6) "blue"
  }
  [3]=>
  array(2) {
    ["value"]=>
    string(1) "3"
    ["label"]=>
    string(6) "green"
  }
}