I am about to set up an online store and I am kinda "testing" if magento (1.7., Community Edition) fits my needs. I think I got the idea behind categorizing and attributing products. But I have a question to the attributes concerning products – or in detail: for configurable products.
Is it possible to "inherit" attribute values (options) from another existing attribute?
I'll give you an example to visualize my question:
Let's say we sell boxes. We would have three different types of boxes:
- uni-color boxes ("box-color")
- boxes with a seperate "top-color"
- boxes with a special printing on it, which has its own color ("highlight color")
To assign colors to box type #1, I would have the possible values
- black,
- white,
- orange.
Box type #2 might come as
- black box / black top (it might seem redundant, but there is a difference to uni-colored boxes),
- black box / white top,
- black box / orange top,
- white box / black top,
- white box / white top,
- white box / orange top,
- and so on.
And finally, box type #3 might come as
- black box / black top / black highlight,
- black / white / orange,
- black / black / white,
- etc.
I think you get the idea.
I would like to have one attribute of color-options which I would maintain (like add new colors, delete old ones, etc.) – and use it as all three different types of configurable color sets.
To be able to create configurable products I would add the color-attribute to my special "boxes" attribute set(s). But when it comes to the two-colored-boxes, I am not able to add the color attribute a second time.
Is there any other (simple) way to achieve this? Since I am new to Magento I would not like to dig too deep into the code or even want to develop a module (?).
Thanks in advance, I appreciate your answers 🙂
Best Answer
Magento gives the support for what you need but it's kind of a long shot.
You are able to set a different source model to your dropdowns.
Let's take for example the attribute
tax_class_id
. It's a dropdown but it does not have the values stored in the database (tableseav_attribute_option
andeav_attribute_option_value
). The source model istax/class_source_product
that in a non-customized instance translates to classMage_Tax_Model_Class_Source_Product
.In the case of
tax_class_id
the options shown in the dropdown are the result ofMage_Tax_Model_Class_Source_Product::getAllOptions()
.You can create a custom extension with a custom model (or 3 - one for each attribute). Set those models to be the source model for your attributes and add your logic inside the
getAllOptions()
method. In this method you can get the values from a table or hard code them, even get them through an external API.Your custom source models should extend
Mage_Eav_Model_Entity_Attribute_Source_Abstract
and should have the following methods:getAllOptions()
- this is where the logic is. This should return an array of arrays. the array at the lower level should look likearray('value'=>'SOME NUMBER HERE', 'label'=>'Label here');
getOptionText()
should be similar to the one inMage_Tax_Model_Class_Source_Product
toOptionArray()
similar to the one inMage_Tax_Model_Class_Source_Product
.getFlatColums()
similar to the one inMage_Tax_Model_Class_Source_Product
just change the column commentgetFlatUpdateSelect()
similar to the one inMage_Tax_Model_Class_Source_Product
Check this for a small tutorial on how to add an attribute with custom options
Also follow how the source model for
tax_class_id
is made. It helps.