Question

I am trying to add new attribute value option, I have read many articles but still I can't achieve what I want, please any idea.

enter image description here

In the attached page you will see a new field I called it description, I need this field to be saved for every option value in my magento database.

Please note that I have used magento 1.9.2.4

Thank you in advance

Was it helpful?

Solution

The product attributes support custom source models.
This means that you can show the options from other sources other than just by filling them in in the attribute edit screen.
Take for example the tax_class_id attribute.
For it, you see as options the tax classes you fill in in the tax management section.
You can do the same for your attribute.
You can create a custom CRUD module with a custom entity, that contains a title, a description and a sort order field.
Then you need to create your attribute via an install script.
Here is a full example on how to create an attribute with a custom source model.

What you need to replace in that script is the method getAllOptions and make it read the values from your database.

public function getAllOptions($withEmpty = false){
    if (is_null($this->_options)) {
        $this->_options = Mage::getModel('[namespace]/[module]')->getCollection()->toOptionArray();
    }
    $options = $this->_options;
    if ($withEmpty) {
        array_unshift($options, array('value'=>'', 'label'=>''));
    }
    return $options;
}

If you don't want to code that yourself, I can recommend the use of a module creator.
It allows you to create your custom entity just like you would create a db table using phpMyAdmin, by defining the attributes/fields you need in the entity, and you can tell it to make this entity a product attribute.

You can find the full documentation of the module in here.

Using this, you won't need to do all kind of tricks to display or not a description field. You can enter the description for your own attribute options in a separate admin section.

This should not be considered as self promotion. The extension I recommended is free and I get no financial benefits if you use it. I also don't get any revenue from the blog I linked.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top