We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    Create one php file inside your Magento root directory with below code.

    <?php
    
    use MagentoFrameworkAppBootstrap;
    
    require 'app/bootstrap.php';
    $bootstrap = Bootstrap::create(BP, $_SERVER);
    $objectManager = $bootstrap->getObjectManager();
    $instance = MagentoFrameworkAppObjectManager::getInstance();
    $state = $objectManager->get('MagentoFrameworkAppState');
    $state->setAreaCode('frontend');
    
    $productCollectionFactory = $objectManager->get('MagentoCatalogModelResourceModelProductCollectionFactory');
    $collection = $productCollectionFactory->create();
    $collection->addAttributeToSelect('*');
     
    // filter current website products
    $collection->addWebsiteFilter();
     
    // filter current store products
    $collection->addStoreFilter();
     
    // set visibility filter
    $collection->setVisibility($objectManager->get('MagentoCatalogModelProductVisibility')->getVisibleInSiteIds());
    $header = array("ID", "Product Name", "Sku","Image", "Main Image");	
    $fp = fopen('evhr-products.csv', 'w+');
    fputcsv($fp, $header);
    $productdata = array();
    $collection->setPageSize(5000); 
        foreach ($collection as $product) { 
        $productsku = $product->getSku();
        $productname = $product->getName();
        $product_id = $product->getId();
    	$productimages = array();
    	$product = $objectManager ->create('MagentoCatalogModelProduct')->load($product_id);
    	$productimages = $product->getMediaGalleryImages();
    	$allimgarray = array();
    	$productImage = $product->getData('image');
    	$productBase = 1;
    	foreach($productimages as $productimage)
    	{
    		if($productimage['file'] == $productImage){
    			$data = array('id' => $product_id, 'productname' => $productname, 'productsku' => $productsku, 'productImage' => $productimage['file'], 'mainimage' => 1 );
    		}else{
    			$data = array('id' => $product_id, 'productname' => $productname, 'productsku' => $productsku, 'productImage' => $productimage['file'], 'mainimage' => 0 );
    
    		}
    		fputcsv($fp, $data);
    	}
    }

     

    field_5bfb909c5ccae

      Get a Free Quote