75
votes
Accepted
Magento 2 - How to get attribute options value of eav entity?
you can add to the constructor of your class an instance of \Magento\Eav\Model\Config like this:
protected $eavConfig;
public function __construct(
...
\Magento\Eav\Model\Config $eavConfig,
...
40
votes
Accepted
When we look at an eavSetup what values are available for type and input?
You can find type and input value from the database eav_attribute table.
Type
datetime
decimal
int
static
text
varchar
Input
boolean
date
gallery
hidden
image
media_image
multiline
multiselect
...
27
votes
Accepted
Magento 2: Are Flat Tables Still a Thing?
Yes, flat tables are still a thing. You can enable flat tables for products and categories from stores->configuration->catalog->storefront.
Why do we need flat tables?
They do offer significant ...
22
votes
Find the table for custom attribute values
When you create an attribute for a product, EAV (Entity Attribute Value) comes into the picture. To get a value you need to know the basic ways Magento stores EAV data.
For this, the following tables ...
20
votes
Accepted
What are entities in Magento 2?
The eav_attribute table's column entity_type_id is mapped to the eav_entity_type table, you can see the entities there.
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
Make Magento 2 Product Attribute Read-Only
Starting from 2.1 Magento uses UI component to build product admin form.
Thus, it should be customized as suggested in the manual.
In particular, your task could be accomplished with modifier ...
11
votes
Accepted
Custom Attribute and value not Appearing in Flat Product table if Attribute is not in...Product Listing,Product Listing,Layered Navigation
Only the attributes that are marked to be used in product listing are copyed to the flat tables. Mark it like this and reindex everything.
11
votes
Set dropdown value using text value
This is untested but should work:
$colourId = $product->getResource()->getAttribute("colour")->getSource()->getOptionId("red");
$product->setColour($colourId)->save();
11
votes
Accepted
Magento 2 : How to Get all User Defined Attributes in Product Model
We should use Service Contracts Layer.
/**
* @var \Magento\Framework\Api\SearchCriteriaBuilder
*/
protected $searchCriteriaBuilder;
/**
* @var \Magento\Eav\Api\AttributeRepositoryInterface
*/
...
11
votes
Accepted
row_id vs entity_id in magento 2.3 EE
Time Dimension
row_id is used to facilitate the Time Dimension for entities that support it. By having this additional identifier, it allows an entity (product, category, sales rule, etc..) to be ...
10
votes
Magento 2 - How to get attribute options value of eav entity?
Use the following code to get all attribute options.
function getExistingOptions( $object_Manager ) {
$eavConfig = $object_Manager->get('\Magento\Eav\Model\Config');
$attribute = $eavConfig->...
10
votes
Magento 2 - Add custom attribute in customer registration form
If your install data script successfully installed your custom attribute, now you just need to override addition information phtml file and set your custom attribute in that.
Create Vendor/TestModule/...
9
votes
Magento 2 Fail to save the value of a newly added Yes/No customer attribute
I found the answer finally.
adding:
$attributeMyhkt->addData([
'attribute_set_id' => 1,
'attribute_group_id' => 1
]);
below:
$attribute->...
9
votes
Setting attribute labels programmatically
You can set the frontend labels with the following code in your UpgradeData or InstallData script:
/** @var \Magento\Eav\Setup\EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->...
8
votes
Accepted
Magento2 Create eav_attribute for catalog
Place InstallData.php file in your module's Setup directory:
<?php
namespace Training\Product\Setup;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\...
8
votes
Magento 2: Are Flat Tables Still a Thing?
Based on magento documentation for flat table mentioned in https://docs.magento.com/m2/ce/user_guide/catalog/catalog-flat.html
Starting with Magento 2.3.0+, the use of a flat catalog is no longer a ...
7
votes
Why attributes of bundle items of a bundle product are also saved to the bundle product itself? (database-wise)
Update: how to stop the indexer from including child products
Extend and modify
Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract.
Look for the function _prepareRelationIndex().
Modify the SQL ...
7
votes
get the deleted attribute back to the live site
You don't need to delete the full eav_attribute table.
Just restore your backup in a different database.
Export your age attribute. You can use phpmyadmin, it's easier.
You should get something like ...
7
votes
Accepted
Get `entity_type_id` by `entity_type_code`
To do so you need to use Magento/Eav/Model/Config class.
Here's some code using the object manager (it is not recommended, please use dependency injection in your final code)
$entityTypeId = $...
7
votes
Attribute property 'system' - what it exactly does
If some attribute is flagged as "is_system" = true
Then such attribute deny to change some specific options on attribute edit page, as shown below
vendor/magento/module-customer-custom-attributes/...
7
votes
Accepted
What is the use of the is_data_sharing field in eav_entity_type?
I may be wrong, but I think for now it does nothing.
Maybe it's the start of a feature that didn't get implemented yet.
I've searched in the code for anything matching is_data_sharing, isDataSharing ...
7
votes
What is the right way to get both, the admin translation and the frontend value of a multiselect attribute?
Assuming your attribute options are coming from a table, and I assume they are because you reference admin and store values, we should be able to call \Magento\Eav\Model\Entity\Attribute\Source\Table::...
6
votes
Accepted
Change increment customer ID from 1 to 00001 with zero padding
I would strongly advise against altering core tables or their auto increment. Instead translate it when retrieved for export/import using str_pad or sprintf i.e.:
$id = 1;
$exportId = str_pad($id, 5, ...
6
votes
Source Model not found for Attribute
For those who might have this issue, I solved it by another way.
It happened when I disabled a module and some attributes were still trying to be launched in db, even if they were useless.
what i did ...
6
votes
Accepted
The _data of an EAV model
In theory _data can contain anything.
You can add your custom values in there by using setData($key, $value).
Usually it contains like you said, the values for the columns in the table, or for ...
6
votes
Magento 2 - How to get attribute options value of eav entity?
I use the Api Service Layer Magento\Eav\Api\AttributeRepositoryInterface suggested by @kandy in comments on @marius answer.
Inject the service data member in your constructor as follow.
protected $...
6
votes
Accepted
Attribute property 'system' - what it exactly does
System attributes are the default attributes shipped natively with the software.
The purpose is to be able to differentiate Magento system attributes and custom attributes.
I reckon it is similar to ...
6
votes
Accepted
Magento 2: What is the difference between the row_id and entity_id in the %_entity tables?
From what I have found on this one, row_id is the identifier for the row, while entity_id is the actual entity.
There are situations where a Scheduled Update is set to run for a fixed period and in ...
6
votes
Magento 2: Schema Changes for EE Catalog Staging
I can't reference the code on account of EE licensing, but in short: Yes. Magento Enterprise Edition 2.1.0 introduced a new 'content staging' feature, which involves some quite invasive changes to the ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
eav × 364magento2 × 136
attributes × 88
magento-1.9 × 68
database × 58
product-attribute × 30
eav-attributes × 28
customer × 26
collection × 21
product × 18
magento-2.1 × 16
custom-attributes × 16
customer-attribute × 16
magento-1.7 × 15
model × 13
module × 12
magento-1.8 × 11
category × 11
magento-1 × 11
flat-catalog × 11
catalog × 10
sql × 9
category-attribute × 9
entities × 9
admin × 7