I am developing an extension for Magento 2 and would like to get all the properties/attributes of the products in the cart. The code needs to be generic so that it can adapt to any kind of product.

For example, if a T shirt is added, I need to get color & size and if a Ring is added, I need to get MetalType, Purity and similar attributes. I am able to get all possible options, but not the attributes of the selected product.

1 Answer 1


I was finally able to achieve this using the following lines:

$options = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
        $itemProps = array();
        if(array_key_exists('attributes_info', $options)) {
                $attributes = $options['attributes_info'];
                 foreach($attributes as $attribute) {
                        $itemProps[$attribute['label']] =  $attribute['value'];

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.