How to Get Product Attribute Set Name in Magento 2
The list of attributes that define the characteristics of a product is called attribute sets. Any information that makes the product unique can be displayed using product attributes.
For a store with thousands of products, it can be tiresome to handle its information like attributes, attribute sets, etc. And, a store owner often needs to get the details of the attribute set in order to update the product or for displaying it categorically in the frontend based on its properties.
Be it for updating the products or improving the in-store experience, it is often the admin’s requirement to get product attribute set name in Magento 2 and the post shows the programmatic solution for the same.
Steps to Get Product Attribute Set Name in Magento 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
use Magento\Catalog\Model\Product; use Magento\Eav\Api\AttributeSetRepositoryInterface; protected $product; protected $attributeSetRepository; public function __construct( Product $product, AttributeSetRepositoryInterface $attributeSetRepository) { $this->product = $product; $this->attributeSetRepository = $attributeSetRepository; } public function getAttributeSetName($productId) { $product = $this->product->load($productId); $attributeSet = $this->attributeSetRepository->get($product->getAttributeSetId()); return $attributeSet->getAttributeSetName(); } |
That’s it.
If you have any doubts, just mention them in the Comments section below.
I would be happy to help.
Feel free to share the solution with Magento community via social media.
Thank You.
Related Post – How to Create Attribute Set Programmatically in Magento 2
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
Prev
How to Add Inline Edit in UI Grid in Magento 2 Backend
Solved: Failed to Open Stream Error While Compiling PluginListGenerator.php in Magento 2.4.1
Next