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="...
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'...
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....
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 ...
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>
<...
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 ...
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)...
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">
&...
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->...
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 ...
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 ...
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]\...
20
votes
Accepted
Magento 2: get attribute label (considering current store view)
Use getStoreLabel() ,instead of getFrontendLabel()
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->...
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\...
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->...
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 > ...
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 ...
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' ...
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');
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 ...
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 ...
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.
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 ...
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. ...
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 ...
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 (\...
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”. ...
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 ...
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
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
attributes × 2266magento2 × 677
magento-1.9 × 459
product-attribute × 339
product × 257
layered-navigation × 120
configurable-product × 119
filter × 101
custom-attributes × 101
customer × 100
category × 91
attribute-set × 91
eav × 88
magento-1.7 × 87
collection × 87
database × 81
magento-2.1 × 71
php × 63
magento2.3 × 62
magento-1 × 60
magento-1.8 × 55
admin × 54
custom × 53
dropdown-attribute × 52
customer-attribute × 44