Is there a simple way to get the attribute code, that a configurable product is configured by?
-
can you give an example of what you need?– Marius ♦Commented Apr 24, 2018 at 7:57
-
I don't think that I can give an example in this case. I just need to get the attribute code I mentioned, assuming that I have loaded the configurable product object.– zekiaCommented Apr 24, 2018 at 8:02
-
but a product can be configured by multiple attributes. You want all available attributes, or something else?– Marius ♦Commented Apr 24, 2018 at 8:04
-
If there are more than one attributes used for configuration, then yes I'd like to get them all. If there's only one attribute used, then just get this one.– zekiaCommented Apr 24, 2018 at 8:08
Add a comment
|
1 Answer
Let's say that $product
is your configurable product.
You can do this:
$usedProductAttribtues = $product->getTypeInstance()->getUsedProductAttributes($product);
This will give you an array where the keys are the attribute ids and the values are instances of the attributes.
If you want the codes you can do this:
$codes = array();
foreach ($usedProductAttribtues as $attribute) {
$codes[] = $attribute->getAttributeCode();
}