81 votes
Accepted

Get product attribute in cart in Magento2

There is no necessity to change any PHP code for doing this. You just need to create {MODULE_NAME}/etc/catalog_attributes.xml with such content: <?xml version="1.0"?> <config xmlns:xsi="...
Igor Sydorenko's user avatar
45 votes
Accepted

Magento 2 : Get Custom Attribute Value of Product

To fetch value of attribute Use: First get Your Product Collection and then $this->getProduct()->getAttributeText('attribute_text'); e.g: $this->getProduct()->getAttributeText('metal_pads'...
Sameer Bhayani's user avatar
31 votes

addFieldToFilter() with OR Condition in magento2

I assume that in your example, yellow, small and china are options in dropdowns. You will need their ids first, but let's assume the are $yellowId, $smallId and $chinaId. You can try this filtering....
Marius's user avatar
  • 197k
28 votes
Accepted

Magento 2: what is the catalog_attributes.xml file?

In general, these files contain a list of attributes that serve different purposes. The group used_in_autogeneration from the file in catalog module serves for listing attributes that have the value ...
Marius's user avatar
  • 197k
27 votes
Accepted

Get Attribute of products of the products in cart at onestepcheckout

Load product in foreach is a bad idea, though working. Better way: in config.xml <global> <sales> <quote> <item> <...
Neklo.com's user avatar
  • 2,379
25 votes
Accepted

Magento 2 how to save custom field added in the form of customer group?

Extension attributes mechanism should be used in this case. It allows extension of core APIs by 3rd party modules. Generic steps for enabling new extension attribute: Declare extension attribute as ...
Alex Paliarush's user avatar
25 votes
Accepted

Magento 2: How to display custom attribute in catalog?

We can get custom attribute value like below Attribute Value <?php /* @escapeNotVerified */ echo $_product->getResource()->getAttribute('c_address')->getFrontend()->getValue($_product)...
Bilal Usean's user avatar
  • 9,837
24 votes

Magento 2 - How to get attribute of product?

Best practice in magento is to do it via xml. To get a standard attribute you do something like this in catalog_product_view.xml for example: <referenceContainer name="product.info.main"> &...
Claudiu Creanga's user avatar
24 votes
Accepted

Magento 2 - How to get attribute of product?

Another way, for the custom attributes: we can simply get the value by using getCustomAttribute() if (null !== $product->getCustomAttribute('your_custom_attribute')) { echo $product->...
Khoa TruongDinh's user avatar
23 votes

Magento 2: Delete magento product attributes?

If you do not see the delete attribute button then that means the table column 'is_user_defined' in the eav_attribute table is set to 0. By changing this to 1 it will show the delete button. If you ...
danmentzer's user avatar
23 votes
Accepted

Best way to update product's attribute value

I have used method updateAttributes of class \Magento\Catalog\Model\ResourceModel\Product\Action. Method can update multiple products and attribute values, but if you want to update just one product ...
Bartosz Kubicki's user avatar
21 votes

Magento2 : Create multi select category attribute with custom source

For a mult select attribute, you can need to add below at your installer: source model: [VendorName]\[ModuleName]\Model\Category\Attribute\Source\Custom.php backend Model [VendorName]\[ModuleName]\...
Amit Bera's user avatar
  • 76.7k
20 votes
Accepted

Magento 2: get attribute label (considering current store view)

Use getStoreLabel() ,instead of getFrontendLabel()
Amit Bera's user avatar
  • 76.7k
19 votes
Accepted

Get attribute value/id from attribute text/label

Get attribute value/id from attribute text/label: $attr = 'your_attribute'; $_product = Mage::getModel('catalog/product'); $attr = $_product->getResource()->getAttribute($attr); if ($attr->...
Manashvi Birla's user avatar
17 votes
Accepted

How to save customer attribute value in custom script in Magento 2

This is how it can be done with customer save method: /** @var \Magento\Customer\Model\CustomerFactory $customerFactory */ /** @var \Magento\Customer\Model\Customer $customer */ /** @var \Magento\...
Daniel Ifrim's user avatar
  • 3,354
15 votes
Accepted

Remove category attribute

You need to create a different upgrade script. If the install script has the version 0.1.0 create the file upgrade-0.1.0-0.1.1.php with this content: $installer = $this; $installer->...
Marius's user avatar
  • 197k
14 votes

Magento 2: How to display custom attribute in catalog?

I created an article about this, that have only 5 steps to do it: 1 - Create your attribute in Stores > Attributes > Product. 2 - Set the attribute in the Default group, go to Stores > Attributes > ...
Rafael Corrêa Gomes's user avatar
14 votes
Accepted

Configurable product attribute sort order in Dropdown 2.12

I faced the same attribute options sorting issue at front-end, As I checked this issue and found that while fetching the attribute options, there is no sorting filter added in the query by default in ...
Jagdish Ram's user avatar
14 votes
Accepted

Magento2 custom attribute for specific product type

Yes , You can create specific attribute for specific product type programmatically. Below i have created Boolean type of attribute for configurable product only. You need to pass 'apply_to' ...
Manthan Dave's user avatar
  • 9,766
13 votes

Magento 2 - How to get attribute of product?

I had solution for my issue: $product = $this->productRepository->getById($product); $attr = $product->getData('status');
MrTo-Kane's user avatar
  • 3,616
13 votes

Options values of attribute "visibility"

These are constants, held in the class Mage_Catalog_Model_Product_Visibility const VISIBILITY_NOT_VISIBLE = 1; const VISIBILITY_IN_CATALOG = 2; const VISIBILITY_IN_SEARCH = 3; const ...
ProxiBlue's user avatar
  • 9,896
13 votes

Magento 2: new attribute not showing in list configurable product

If you want to use an Attribute for Configurations, you have to make sure, that it has the Scope Global. That is (I think) like this, because it does not make sense to override a configuration ...
David Verholen's user avatar
13 votes
Accepted

"Undefined Index Notice" in EavAttribute.php when adding a swatch option

Looks like problem in server settings. Please try increase max_input_vars setting to 100000 and try reproduce problem.
KAndy's user avatar
  • 20.6k
13 votes
Accepted

Change order of configuration options in customer product view

The position of the attributes of Configurable Product are stored at catalog_product_super_attribute Use SQL to update position in PDP 192 = Id attribute Size 193 = Id Attribute Color update ...
HoangHieu's user avatar
  • 1,284
12 votes
Accepted

What is difference between filterable with result and Filterable with no result in magento Attributes

use for layered navigation. Filterable (with results) means that links will only appear for values where the number of results (the number in parentheses next to each value) is greater than zero. ...
Qaisar Satti's user avatar
  • 32.3k
12 votes

Magento 2 How to uninstall attributes added by custom module?

In a module, you would use the following code that utilizes dependency injection for uninstallation. It works equally well anywhere else, just be sure to inject the EavSetupFactory into the ...
CarComp's user avatar
  • 1,216
12 votes
Accepted

Whats the best way to check if a custom attribute exists in Magento2

You need use \Magento\Eav\Api\AttributeRepositoryInterface::get method for this. For example: try { $attribute = $this->attributeRepository->get($entityType, $attributeCode); } catch (\...
KAndy's user avatar
  • 20.6k
12 votes
Accepted

"discount_tax_compensation_amount" attribute in Sales Order Item (Magento 2)

It is used by Magento to calculate the amount of tax that is not originally calculated when a product that has a tax is under discount. For example. Let’s suppose you have a product named “Pencil”. ...
Kavitha mano's user avatar
12 votes
Accepted

how to save image custom attribute in magento 2

In your observer there is a lot of unnecessary code. You can change it like: <?php namespace Dcw\Vm\Observer; use Magento\Framework\Event\ObserverInterface; class ProductSaveAfter implements ...
Siarhey Uchukhlebau's user avatar
12 votes
Accepted

Magento 2 : How to know "used_in_forms" param of eav attribute for a form?

You can get all used_in_forms in magento by typing below query, Used in form customer attribute: SELECT DISTINCT form_code FROM customer_form_attribute WHERE 1 adminhtml_checkout ...
Rakesh Jesadiya's user avatar

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