我想以编程方式了解magento属性是否使用选项以了解是否必须显示此选项。
例如,Text属性不使用它,Dropdown属性有选项。但是如何通过编程方式进行区分?
答案 0 :(得分:0)
$product = Mage::getModel('catalog/product')->load($product_id);if($product->hasOptions){
$optionsArr = $product->getOptions();
foreach($optionsArr as $optionKey => $optionVal)
{
$options=array();
foreach($optionVal->getValues() as $valuesKey => $valuesVal)
{
$options[]=array("key"=>$valuesVal->getId(), "val"=>$valuesVal->getTitle());
}
$custom_option["titles"][]=array("title"=>$optionVal->getTitle(),"title_id"=>$optionVal->getId(),"options"=>$options);
//$optStr.= "</select>";
}
答案 1 :(得分:0)
$attributeCode = 'code_here';
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attributeCode);
if ($attribute->getSourceModel()) {
//it has options
} else {
//it does not have options
}
答案 2 :(得分:0)
$attributeModel = Mage::getModel ( 'eav/entity_attribute' )->loadByCode ( 'catalog_product', 'attribute_code' );
if ($attributeModel->getData ( 'frontend_input' ) == 'select') {
$attribute = Mage::getSingleton ( 'eav/config' )->getAttribute ( 'catalog_product', 'attribute_code' );
if ($attribute->usesSource ()) {
$options = $attribute->getSource ()->getAllOptions ( false );
$ifoptionfound = false;
if($options)
$ifoptionfound = true;
}
}