When working on Adobe Commerce (Magento Cloud), there are occasions when we need to use the product’s internal ID rather than its regular ID.
In Adobe Commerce (the premium version), this internal ID is referred to as the row ID, and it’s used for features like scheduling and staging content – essentially, for managing versions of products that are published at different times.
In the community (Open source) version, this same value is simply known as the entity ID.
We’re able to access this internal ID by using a built-in Magento tool, which makes it straightforward to retrieve when needed.
Please check the code to fetch the row_id value.
<?php declare(strict_types=1); namespace Rbj\Test\Model; use Magento\Catalog\Model\Product; use Magento\Catalog\Api\Data\ProductInterface; use Magento\Framework\EntityManager\MetadataPool; class GetRowIdByProduct { public function __construct( private readonly MetadataPool $metadataPool ) {} public function getRowIdValueFromProduct(Product $product): int { $metadata = $this->metadataPool->getMetadata(ProductInterface::class); return (int) $product->getData($metadata->getLinkField()); // row_id return for $metadata->getLinkField() in commerce/cloud } }
Thank you.