I have an extension that works with product Ids instead of product SKUs for import for which i need to export product ids along with the SKUs to match the products. As far i have checked there is no option to export product entity_id from magento 2 backend and also the script examples available are with magento 1.9 or lower version. Please suggest if there i a way to accomplish this with custom coding or extension.
Thanks
3 Answers 3
You may retrieve all of products via API.
/V1/products?searchCriteria
<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory')->create();
$productCollection->addAttributeToSelect('sku');
$productCollection->addAttributeToSelect('entity_id');
$csvFile = fopen('product_ids.csv', 'w');
fputcsv($csvFile, ['SKU', 'Product ID']);
foreach ($productCollection as $product) {
fputcsv($csvFile, [$product->getSku(), $product->getId()]);
}
fclose($csvFile);
In this code, we're using the Product\CollectionFactory object to retrieve a collection of products. We then add the sku and entity_id attributes to the collection's selection. We iterate over the collection and write the SKU and product ID values to a CSV file.
Make sure to place this code in a PHP file, locate it in the root directory of your Magento installation, and run it from the command line or by accessing the file through a browser. The resulting CSV file will contain the exported SKUs and product IDs.
Remember to adjust the file permissions as needed and customize the export format according to your preferences.
I hope this meets your requirements!
Just Export Database Table: catalog_product_entity
Explore related questions
See similar questions with these tags.