I have got an object of this model magento/catalog/model/product and I want to use one of the EAV attributes values of it. How to access this EAV attribute through model object.There is no issue with non-EAV attributes to be used.


You should use code like:

$product = $productRepo->get($productId); 
$attributeValueId = $product->getCustomAttribute('my_custom_attribute_code');
| improve this answer | |
  • I'm manipulating a helper in magento2 core. There, I already have have that loaded product. I also want to have access to EAV product attributes. what shall I do then? – Amin Memariani May 29 '16 at 9:30
  • you can use $product->getCustomAttribute('my_custom_attribute_code'); but if product loaded not from repo, attribute will not be loaded – KAndy May 29 '16 at 10:13
  • the product does not load from repo! it has been loaded from magento/catalog/model/product. So how can I load EAV attribute? Is there any appropriate solution? – Amin Memariani May 29 '16 at 10:44
  • 1
    @AminMemariani try $product->getData('attribute_code'); – Yogesh Agarwal Sep 7 '17 at 11:43

You can create a new helper, add the product repository in the constructor and get eav custom attributes from here. Please check details in this post : Get product attribute in cart in Magento2

| improve this answer | |

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.