Skip to main content
22 votes
Accepted

magento 2 - How to get attribute set name in product listing and product detail page

We can use \Magento\Eav\Api\AttributeSetRepositoryInterface to get attribute set name. Detail Page We need to override the \Magento\Catalog\Block\Product\View block. Inject this class on the ...
Khoa TruongDinh's user avatar
21 votes
Accepted

Magento 2 Get a list of Attribute Set Names and IDs

The best way to get it is to use the following source model : \Magento\Catalog\Model\Product\AttributeSet\Options You can inject it in your constructor then call the toOptionArray() method to ...
Raphael at Digital Pianism's user avatar
19 votes
Accepted

How to show the drop down attribute value using getData() method in magento 2?

Instead of getData() you need to use getAttributeText('attribute_code') for dropdown attributes. like $_product->getAttributeText('material'); For multi-select try this : $result = $_product-&...
Ashish Jagnani's user avatar
12 votes
Accepted

How to retrieve custom attribute set ID by name

You can retrieve attribute set ID by using following code: protected $_attributeSetCollection; public function __construct( ... ,\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\...
Rizwan Dhuka's user avatar
12 votes
Accepted

Magento : Filter Collection by Attribute that Doesn't Exist or Null or another condition

After some tests, the code I wrote in the third edit of the question seems to work fine, so I think it is the correct answer: $_products = Mage::getModel('catalog/product') ->getCollection() -&...
Alex's user avatar
  • 811
12 votes
Accepted

How to get the attribute id by attribute code in magento 2

Get Attribute Id By Attribute Code In Magento2. Just you have to follow some steps. public function __construct( Context $context, private readonly \Magento\Eav\Model\ResourceModel\Entity\...
Nikunj Vadariya's user avatar
9 votes

How to retrieve custom attribute set ID by name

Based on Rizwan Dhuka answer, you can: reduce response size with select 'attribute_set_id' instead of '*' avoid a loop on the object with combine getFirstItem and toArray methods namespace ...
Nolwennig's user avatar
  • 521
8 votes

Magento 2: How to Change Default Attribute Set & Set Our Own

1.Find id of "Attribute Set" in database column eav_attribute_set.attribute_set_id 2.UPDATE `eav_entity_type` SET `default_attribute_set_id` = '%YOUR_Attribute_Set_ID%' WHERE `eav_entity_type`.`...
SadMagento's user avatar
8 votes

Please re-run Magento compile command?

Depending on your configuration it may also be unecessary. If you are in default or dev mode you do not need it. You just need it on production mode From command line and from your Magento root path:...
Phoenix128_RiccardoT's user avatar
8 votes

How to show the drop down attribute value using getData() method in magento 2?

You can get product attribute option values by below code $_product->getAttributeText('material'); You can get multi select option values by $_attributeValue = $block->getProduct()->...
Suresh Chikani's user avatar
8 votes

How to show the drop down attribute value using getData() method in magento 2?

To fetch value of attribute Use: $this->getProduct()->getAttributeText('material'); Or $this->getProduct()->getResource()->getAttributeRawValue($this->getProduct()->getId(),'...
Sameer Bhayani's user avatar
7 votes
Accepted

magento2 create customer attribute

Please make below change in module.xml, <?xml version="1.0" encoding="UTF-8"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../...
Rushvi's user avatar
  • 2,843
7 votes
Accepted

Programmatically add Custom Product Attribute to attribute set

Try this <?php $installer = new Mage_Eav_Model_Entity_Setup('core_setup'); $installer->startSetup(); $installer->addAttribute('catalog_product', 'pim_id', array( 'group' ...
Abdul's user avatar
  • 9,701
6 votes
Accepted

How do you remove the short product description from the product page Magento 2

You remove it in layout xml. Make the file {theme_dir}/Magento_Catalog/layout/catalog_product_view.xml with this contents: <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/...
Aaron Allen's user avatar
  • 9,009
6 votes
Accepted

Magento 2 : How to get attribute group id using attribute set id ?

Block function public function getAttributeGroupId($attributeSetId) { $obj = \Magento\Framework\App\ObjectManager::getInstance(); /** @var \Magento\Catalog\Model\Config $config *...
Nitin Pawar's user avatar
  • 1,566
5 votes

How to get the attribute id by attribute code in magento 2

You can also use a product attribute repository class to do this: public function __construct( \Magento\Catalog\Api\ProductAttributeRepositoryInterface $productAttributeRepository, ) { $this-&...
Andrew Kett's user avatar
  • 3,508
5 votes

Magento2 How can get the Attributes based on the Attribute Set Id or Attribute Set Name

you can make use of the Magento\Catalog\Api\ProductAttributeManagementInterface $attributeSetId = 20;//your_attributeSetId $productAttributesManagement = $this->objectManager->create('Magento\...
Vincent L'Ecluse's user avatar
4 votes

How to get attributes by attribute set ID in Magento 2?

You can use the Magento\Eav\Api\AttributeManagementInterface service contract class: $attributeManagementInterface->getAttributes(\Magento\Catalog\Api\Data\ProductAttributeInterface::...
Raphael at Digital Pianism's user avatar
4 votes
Accepted

Create Attribute set in Magento 2 using Api

Magento 2 already have an API point for creating an attribute set. http://www.example.com/rest/V1/products/attribute-sets You have to hit API point and have to post below value { "...
Amit Bera's user avatar
  • 77.6k
4 votes
Accepted

How to Display Attribute value in magento 2 using getProducts() Method

If it is a dropdown attribute then use this: $_item->getProduct()->getAttributeText('weight_spices'); or $_item->getProduct()->getResource()->getAttributeRawValue($this->...
Shoaib Munir's user avatar
  • 9,522
3 votes
Accepted

How to use a Media Image Attribute

Try this, Here desc_logo is attribute id <?php $_product = $objectManager->get('Magento\Catalog\Model\Product')->load($productId); $attrImage = $...
Magento 2's user avatar
  • 3,834
3 votes

Change attribute set of existing products

Yes. We can change product attribute set programmatically. I prefer to create massaction in catalog product grid to multiselect product and then select massaction for the products. Creating ...
Kazim Noorani's user avatar
3 votes

Change attribute set of existing products

Flagbit-ChangeAttributeSet just wasn't updated at Magento Connect. Make sure to use version from Github. It definitly works for Magento 1.9. this is not good, better you recreate the product, even ...
sv3n's user avatar
  • 11.7k
3 votes
Accepted

Magento 2: How to override Magento\Catalog\Block\Product\View constructor to inject \Magento\Eav\Model\Entity\Attribute\SetFactory

So after taking everyones suggestions and getting as far as being able to render the product detail page without any errors but the block addtocart.phtml would not appear at all. I ran into this ...
Noemi Quezada's user avatar
3 votes

How to show the drop down attribute value using getData() method in magento 2?

$_product->getAttributeText('material'); is the right answer --- beware that $_product->getResource() is a deprecated function
Alex's user avatar
  • 13.9k
3 votes
Accepted

Howto add attribute to multiple attribute sets programmatically in magento2?

Found a simple solution. my method: public function assignAttributeToSets($attribute_code, $attribute_set_ids) { foreach ($attribute_set_ids as $set_id) { $group_id = $this->config-&...
spiilmusic's user avatar
3 votes

Create Product Programatically with different attribute sets

It's very simple to set different attribute set for different roducts in ONE CSV file. On the column attribute_set_code of the product CSV, just indicate the attribute set you want to have. Then enter ...
PY Yick's user avatar
  • 2,705
3 votes

Create Product Programatically with different attribute sets

Pass attribute set name to function argument <div onclick="createP("original")">Original</div> <div onclick="createP("new")">New</div> Create javascript file with ajaxcall &...
S.P's user avatar
  • 1,564
3 votes

In which table the attribute set ids are stored in magento 2

Attribute set ids are store in eav_attribute_set table. Table fields are like below attribute_set_id : attribute set id store. entity_type_id : entity type like customer catalog etc ...
Suresh Chikani's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible