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 Apr 24 '18 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 Apr 24 '18 at 8:02
  • but a product can be configured by multiple attributes. You want all available attributes, or something else? – Marius Apr 24 '18 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 Apr 24 '18 at 8:08

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, privacy policy and cookie policy

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