Home » Miscellaneous10 June 2016

Magento 2: Get All Product Attributes with Name and Value

This article shows how to load product by it’s ID and then get all attributes associated with that product in Magento 2. We print the attribute code, attribute name, and attribute value of all the attributes related to any particular product.

We will be using Magento 2’s Service Layer for this task. Use of Service Layer is highly encouraged by Magento.

Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of \Magento\Catalog\Model\ProductRepository class in the constructor of my module’s block class.


Now, we load the product by id and get all attribute code, attribute name, and attribute value for the product in template file.

Hope this helps. Thanks.


Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • magento

  • jarnail

    values are not displaying : echo $attribute->getFrontend()->getValue($product); – This line doesnt work. How to get values ?

    Great efforts