2

I am trying to add new attribute value option, i have read many articles but still i cant 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 use magento 1.9.2.4

Thank you in advice

  • you plan to use this for every attribute, or you need it for a specific one or two? – Marius Dec 13 '16 at 8:10
  • thank u marius for your response, i need it to be available for a specific attribute – Thaer Dec 13 '16 at 8:15
  • but i think it will not be a problem if the field shown for all attributes, because i can hide it by attribute id – Thaer Dec 13 '16 at 8:18
  • I have a better and easier solution, so you don't have to hide it for some attributes and you don't have to do all kind of js tricks. Give me a few minutes to answer. – Marius Dec 13 '16 at 8:21
1

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.

  • i have the following error after creating the Easylife module Fatal error: Call to undefined method Easylife_Provider_Model_Attribute_Source_Provider::__() – Thaer Dec 13 '16 at 9:11
  • sorry about that. replace $this->__ with Mage::helper('core')->__ – Marius Dec 13 '16 at 9:16
  • i have changed the 'input' => 'select', to be multiselect but it shows me a drop down list with one selection. how i can change the input to be multiselect. about the module creator that you have suggest in your answer, i have downloed and install it but its not shown in the admin panel, but note that its shown in System > Configuration > Advanced > Disable Modules Output ,Finally thank very much for your answer its really helped me :) – Thaer Dec 13 '16 at 9:28
  • clear the cache. – Marius Dec 13 '16 at 9:30
  • Dear Marius, i have one more question please ,every thing working perfectly, i have create an Product Ingredients module and changed the dropdown list to be multiselect with 'eav/entity_attribute_backend_array' , but still not save a multi option selection please help me to find a solution, thank you – Thaer Dec 13 '16 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.