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