Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get product id and sku in magento with SQL

i'm trying to get the product id and the SKU of each product in magento with SQL, i fount that the table catalog_product_entity has all the SKUs but no product id.

like image 814
Abude Avatar asked Feb 08 '13 09:02

Abude


People also ask

How do I get product ID from SKU Magento 2?

$id = YOUR_PRODUCT_ID; $sku = 'YOUR_PRODUCT_SKU'; $_product = $block->getProductById($id); $_product = $block->getProductBySku($sku); echo $_product->getEntityId(); echo '<br />'; echo $_product->getName(); Here is one of the best practices to get product information by product ID or SKU in Magento.

How do I get SQL query in Magento 2?

By default, Magento will automatically connect to its database using class Magento\Framework\App\ResourceConnection with getConnection() function. Calling from a template or other PHP files, You need to use the $this->resourceConnection object to run any Direct SQL Query.

What is SKU in Magento?

What is SKU in Magento. SKU stands for a Stock Keeping unit, and it is a unique identification code in alphanumeric format. It is assigned to every product in an online Magento store for inventory purposes and can identify a product according to its manufacturer, color or size options, price, etc.

How do I find my Magento database name?

Go to your store core folder and open the env. php file under the app/etc folder. Find the next code, where database_name is actual database name which you use for your Magento 2 store.


2 Answers

entity_id is product's unique id so if you call $product->getId(); you actually get entity_id

The reason for that column name is that product is an EAV (Entity Attribute Value) model so product is an entity - standardized EAV entity identification column name but it can bring confusion...

And the query:

SELECT entity_id as product_id, sku FROM catalog_product_entity
like image 76
Domen Vrankar Avatar answered Nov 15 '22 16:11

Domen Vrankar


The column 'entity_id' is the ID for the products. So the catalog_product_entity table does contain both items.

like image 32
Chris Avatar answered Nov 15 '22 16:11

Chris