Вы можете использовать getAttributes()
, который возвращает массив Mage_Eav_Model_Entity_Attribute
.
<?php
$attributes = Mage::getModel('customer/customer')->getAttributes();
foreach ($attributes as $attr) :
?>
<input type="checkbox" name="attributes[]" value="<?php echo $attr->getId() ?>" id="attribute-<?php echo $attr->getId() ?>" />
<label for="attribute-<?php echo $attr->getId() ?>"><?php echo $attr->getStoreLabel() ?></label>
<?php endforeach; ?>
Значительно улучшенная техника для конфигурации:
Сначала нам нужно создать исходную модель в вашем модуле, далее вам, очевидно, придется переименовать ее, чтобы она соответствовала вашему фактическому модулю.
class Your_Module_Model_Source_Customer_Attribute
{
public function toOptionArray()
{
$attributes = Mage::getModel('customer/entity_attribute_collection')
// remove filter to allow default address ID, etc.
->addVisibleFilter();
$result = array();
foreach ($attributes as $attribute) {
if (($label = $attribute->getFrontendLabel()))
$result[$attribute->getId()] = $label;
}
return $result;
}
}
Затем нам нужноодно новое поле в system.xml .
<fieldname translate="label">
<label>Customer Attributes</label>
<frontend_type>checkboxes</frontend_type>
<source_model>yourmodule/source_customer_attribute</source_model>
<show_in_default>1</show_in_default>
</fieldname>
вашего модуля. Это работает на удивление хорошо, удивительно, потому что эти классы не используются в ядре.Вместо checkboxes
тип также может быть radios
, который тоже работает.