How to Export Simple Product CSV Programmatically using custom Scripts.
Create one custom.php File into the root folder.
and put below code into a file and run into the browser.
You can find this CSV inside the root directory
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); ini_set('memory_limit', '5G'); error_reporting(E_ALL); use MagentoFrameworkAppBootstrap; require realpath(__DIR__) . '/../app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap--->getObjectManager(); $state = $objectManager->get('MagentoFrameworkAppState'); $state->setAreaCode('admin'); $registry = $objectManager->get('MagentoFrameworkRegistry'); $registry->register('isSecureArea', true); //Store id of exported products, This is useful when we have multiple stores. $store_id = 4; ("Your Store ID") $fp = fopen("export-simple.csv","w+"); $objectManager = MagentoFrameworkAppObjectManager::getInstance(); /** @var MagentoCatalogModelResourceModelProductCollection $productCollection */ $productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection'); /** Apply filters here */ $collection = $productCollection->addAttributeToSelect('*')->addFieldTofilter('type_id','simple') ->addFieldToFilter('visibility', MagentoCatalogModelProductVisibility::VISIBILITY_BOTH)->load(); foreach ($collection as $product) { $data = array(); //$data[] = $product->getTypeId(); $data[] = $product->getName(); $data[] = $product->getSku(); fputcsv($fp, $data); if ($product->getSize() > 0) { $data = array(); foreach ($products as $product) { //print_r($product->getData()); ("Here You get all Data from collection") $data[] = $child->getName(); $data[] = $child->getSku(); fputcsv($fp, $data); } } } fclose($fp);
About Author:
Kalpesh Chavada
Kalpesh Chavada is Our Founder & CEO of Akshar Group Technologies. He is serving with 11+ years of experience in different technologies like Magento, WordPress, Laravel, jQuery, Shopify, Branding, and Digital Marketing. He is very good with creative logic and always ready to take on challenges.