Edit: I found the mistake. I'll mark answer as soon as I can (2 day's waiting time)
Hope the titel is clear enough... I made a small backend module created with 'Magento UMC'. In one of my Tabs I added a dropdown field with a dummy value which I planned to swap with a collection of all Attribute titles. I actually managed to get that done and I also modified the following file so the right value gets saved in the database:
<?php
class MP_Search_Model_Element_Attribute_Source_Attribute extends Mage_Eav_Model_Entity_Attribute_Source_Table
{
public function getAllOptions($withEmpty = true, $defaultValues = false)
{
$options = array();
$attributeCollection = Mage::getSingleton('eav/config')
->getEntityType(Mage_Catalog_Model_Product::ENTITY)
->getAttributeCollection();
foreach ($attributeCollection as $attribtue) {
array_push($options,
array(
'label' => Mage::helper('mp_search')->__($attribtue->getName()),
'value' => $attribtue->getId()
)
);
}
if ($withEmpty) {
array_unshift($options, array('label'=>'', 'value'=>''));
}
return $options;
}
public function getOptionsArray($withEmpty = true)
{
$options = array();
foreach ($this->getAllOptions($withEmpty) as $option) {
$options[$option['value']] = $option['label'];
}
return $options;
}
public function getOptionText($value)
{
$options = $this->getOptionsArray();
if (!is_array($value)) {
$value = explode(',', $value);
}
$texts = array();
foreach ($value as $v) {
if (isset($options[$v])) {
$texts[] = $options[$v];
}
}
return implode(', ', $texts);
}
}
I only changed the getAllOtions()
method. This is how the original looked:
public function getAllOptions($withEmpty = true, $defaultValues = false)
{
$options = array(
array(
'label' => Mage::helper('mp_search')->__('All Attributes'),
'value' => 1
),
);
if ($withEmpty) {
array_unshift($options, array('label'=>'', 'value'=>''));
}
return $options;
}
I changed the $fieldset->addField()
in the /Tab/Form.php to show all Attributes in the dropdown menu:
class MP_Search_Block_Adminhtml_Element_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$attributeCollection = Mage::getSingleton('eav/config')
->getEntityType(Mage_Catalog_Model_Product::ENTITY)
->getAttributeCollection();
$attributes = array();
foreach($attributeCollection as $attribute) {
array_push($attributes, $attribute->getName());
}
$fieldset->addField(
'attribute',
'select',
array(
'label' => Mage::helper('mp_search')->__('Attribute'),
'name' => 'attribute',
'note' => $this->__('Choose Attribute'),
'required' => true,
'class' => 'required-entry',
'values'=> $attributes,
)
);
I left the Grid.php untouched since all Attributes are shown in the dropdown field. But if I create an item with an Attribute, for example color, the attribute name doesn't appear in the Grid. If I set the attribute filter to 'color' the item also doesn't get shown. So I'm probably missing something here. I checked all the files but I can't tell which one is responsible for this. If more detail is required please tell me, I didn't wanted to post to much at once.