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
11 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

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

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

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,835
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,692
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
  • 8,969
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,526
5 votes
Accepted

Get all Attribute Sets in Static Block

You can get all attribute set list using below code. $entityType = Mage::getModel('catalog/product')->getResource()->getTypeId(); $attributeSetCollection = Mage::getResourceModel('eav/...
Prashant Valanda's user avatar
5 votes

Saving Attribute Sets - Very SLOW

I took a default installation and ran a Blackfire.io test on the save action of the attribute set page. This is the main method I found that takes the bulk of the time ...
Peter Jaap Blaakmeer's user avatar
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
Accepted

Programatically created atrributes on layered navigation

Problem here is that you want to use a text type attribute for magento layered navigation. Magento only supports the int type as valid layered navigation attribute. The types select and multi select ...
Wouter Steenmeijer's user avatar
4 votes
Accepted

How to remove or delete an Attribute from the Default Template (Attribute Set)

You can edit the attribute set in the backend Stores->Attribute set. And edit the desired Attribute set, Now on attribute groups just drag and drop the selected attribute in the left area (unsigned ...
Arunendra's user avatar
  • 7,386
4 votes
Accepted

Running a script only one time

I think it should not be a problem to put the attribute removal intro an sql upgrade script. Just make sure to check if the attribute exists before you remove it. Then you should not have an issue ...
Anna Völkl's user avatar
  • 17.3k
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

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,478
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.2k
3 votes
Accepted

Specific Custom Design Layout for Product Attribute Set

For this case, we can add new layout handler on basic of Attribute Sets at event controller_action_layout_load_before. Event: controller_action_layout_load_before Condition: product attribute set ...
Amit Bera's user avatar
  • 77.2k
3 votes
Accepted

Magmi: Attributes not being associated with attribute sets

Appears I had missed a step, and did not add the magmi:groups column to the attribute set import csv.
Chuck's user avatar
  • 709
3 votes
Accepted

How to change 'choose an option' in magento attribute dropdown

You need to modify configurable.phtml template file for this: copy this file from here : app/design/frontend/base/default/template/catalog/product/view/type/options And paste it in your theme ...
Arunendra's user avatar
  • 7,386
3 votes

Different default value of an attribute in different attribute sets

Interesting question. With default Magento, you can't. But there are ways. I'd recommend creating an extension that listens to the catalog_product_save_before event in the adminhtml scope. Create the ...
Peter Jaap Blaakmeer's user avatar
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
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

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