What is the difference between Product ID and SKU in Magento 2?
3 Answers
Product ID
is an internal unique identifier of a product in Magento which corresponds to the product increment in Magento's database.
You can't set it manually because it is auto-incremented in catalog_product_entity table.
Product SKU
is also a unique product identifier, but it can be set manually by the administrator while creating a product and it shows on the frontend for customers to see, so they can reference the product by SKU.
SKU is also a product attribute, while Product ID isn't.
And it is often used for connecting products between ERP or commercial software and Magento web shops.
-
But I discovered the follwowing in my Magento 2 installation that I fed with Magento Sample Data: I ordered 1 piece of product (sku: MSH12-33-Red). In the quote_item table there are now 2 rows. First Row: [item_id: 51, product_id: 1033, parent_item_id: Null, sku: MSH12-33-Red, name Pierce Gym Short] , Second Row: [item_id: 52, product_id: 1026, parent_item_id: 51, sku: MSH12-33-Red, name Pierce Gym Short-33-Red]. This means there is one sku with different names and pointing to two product ids. This would mean there is no 1:1 relationship between product id and sku, isn't it?– JensCommented Jan 3, 2018 at 14:47
-
1I think you made an order for a simple product which is part of a composite product. A composite (for example a configurable product) usually contains 2 or more simple products. So in your example you ordered a simple product ID 1026 with SKU MSH12-33-Red which is part of the configurable product ID 1033. In Magento's database logic, it writes 2 rows for this order (1 row for the configurable and 1 for the simple product).– LezCommented Jan 3, 2018 at 15:03
Product ID is the primary key of the the product base table. But SKU (Stock Keeping Unit) is a unique value which can also be used to identify a product.
Magento won't allow the store admin to decide the Product ID as it is an auto increment value. But store admin can decide the SKU of his product.
Example data: Product ID will be: 1, 2, 3, .... 100025 etc SKU will be: MY-PRODUCT-001, SOMETHING9089, 100222052 etc..
Hope that make sense.
-
But I discovered the follwowing in my Magento 2 installation that I fed with Magento Sample Data: I ordered 1 piece of product (sku: MSH12-33-Red). In the quote_item table there are now 2 rows. First Row: [item_id: 51, product_id: 1033, parent_item_id: Null, sku: MSH12-33-Red, name Pierce Gym Short] , Second Row: [item_id: 52, product_id: 1026, parent_item_id: 51, sku: MSH12-33-Red, name Pierce Gym Short-33-Red]. This means there is one sku with different names and pointing to two product ids. This would mean there is no 1:1 relationship between product id and sku, isn't it?– JensCommented Jan 3, 2018 at 14:47
-
1This is because you ordered configurable product. Order stores both parent product (configurable) and child (simple) for order you made. So in this case if you will order 2 products you will see 4 order_items. They both will have the same sku which belongs to parent, if I not mistake, but product id will be original. If worry about 1:1 relation - just try to save different product with the same SKU. Commented Jan 3, 2018 at 15:19
they are almost the same for user, but different for developer and for it's purpose. Here is why:
- Product id is used as primary key for DB store.(it's faster for searching and so on)
- SKU used for unique identifier of product
Imagine that you transfer products from one db to another, or you have inventory service that communicate with magento through the web api, primary key is auto-incremented so you would have different product id in different databases for one product, but sku will be the same.