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 ...
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 ...
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-&...
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\...
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()
-&...
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\...
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 ...
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:...
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`.`...
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()->...
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(),'...
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="../../../../../...
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' ...
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/...
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 *...
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/...
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 ...
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\...
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 ...
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 ...
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 ...
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::...
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-&...
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
{
"...
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
...
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.
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 ...
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 ...
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 ...
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 = $...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
attribute-set × 239attributes × 91
product-attribute × 70
magento2 × 61
magento-1.9 × 45
product × 27
configurable-product × 13
custom-attributes × 12
magento-2.1 × 9
magento2.3 × 7
magento-1.8 × 7
category × 7
magento-1 × 7
products × 6
layered-navigation × 6
attribute-group × 6
magento-1.7 × 5
collection × 5
catalog × 5
magento2.2.2 × 5
dropdown-attribute × 5
php × 4
database × 4
magento2.2 × 4
import × 4