Magento – Product Image Not Showing in detail page

magento2magento2-migration-toolmigrationproduct-images

I used Ubertheme migration tool to migration of data from Magento 1 to magento2.
Migration is done successfully, but after that, I face one issue.

Product Image shows in category list page on frontside and product grid in admin side.
When I open product detail page in front and admin side, I am not able to see product image.

Can anyone tell me what should I do?

Best Answer

I found solution using this script,

In above condition, product image are already assign in database but not show in frontend, you can do this using this script.

You need to do following things,

  1. Create one file in magento root directories, let say file name is "Productimage.php"

  2. Put the following code into that file,

    <?php 
    use Magento\Framework\App\Bootstrap;
    require __DIR__ . '/app/bootstrap.php';
    
    $bootstrap = Bootstrap::create(BP, $_SERVER);
    
    $obj = $bootstrap->getObjectManager();
    
    $state = $obj->get('Magento\Framework\App\State');
    $state->setAreaCode('frontend');
    
    try
    {
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $importDir = __DIR__ . '/pub/media/catalog/product';
        $product = $objectManager->get('Magento\Catalog\Model\Product')->load(YOURPRODUCTID);
    
            if($product->getImage() != '')
            {
                $id = $product->getId();
                $url = $importDir . $product->getImage();
                $product->addImageToMediaGallery($url, array('image', 'small_image', 'thumbnail'), true, false);
                $product->save();
                echo "<br /><br /> $id Product Save Succefully";
            }
    
    }
    catch(\Exception $e)
    {
        echo $e->getMessage();
        exit;
    }
    

NOTE: replace YOURPRODUCTID with your real Id.

Related Topic