How to get custom attribute value in magento2
1 Answer
First you need to search his id and his backend_type with this query:
select a.attribute_id, a.attribute_code, a.backend_type
from eav_attribute as a
inner join eav_entity_type as e on (a.entity_type_id = e.entity_type_id)
where e.entity_type_code = 'catalog_product';
The entity_type_code field can be 'catalog_product' for product attributes, 'customer' for customer attributes or 'customer_address' for customer address attributes.
The query will return a set of all attributes linked to a product in magento (default and custom attributes):
+--------------+--------------------------------+--------------+
| attribute_id | attribute_code | backend_type |
+--------------+--------------------------------+--------------+
| 429 | allow_message | int |
| 399 | allow_open_amount | int |
| 578 | brand | int |
| 590 | bundle_price | varchar |
| 581 | bundle_qta | varchar |
| 593 | categoria | int |
...
After you found the attribute_id
and the backend_type
of your attribute you can select his values in on of the catalog_product_entity
tables (depends on the backend type of your attribute).
sql table | backend type
--------------------------------|---------------
catalog_product_entity_int | int
catalog_product_entity_varchar | varchar
catalog_product_entity_decimal | decimal
...
For example if your attribute has the is 578 and the backend_type of int, you execute a query like this one:
select * from catalog_product_entity_int where attribute_id = 578