0

Is there a simple way to get the attribute code, that a configurable product is configured by?

4
  • 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.
    – zekia
    Commented 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.
    – zekia
    Commented Apr 24, 2018 at 8:08

1 Answer 1

1

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();
} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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