Magento – Magento 1.x set thumbnail image same as small image for all products

magento-1.8productproduct-attributeproduct-images

I have imported 77K products in magento with custom import script.
All data are imported successfully.

The mistake I did is I forgot to set Thumbnail image for each product.
We have only two images for each product, so I want to set small image value same as thumbnail image.

Is there anyone who can provide me code to update thumbnail for each product at a time?

Screenshot: enter image description here

I have tried this:

$products = Mage::getModel('catalog/product')->getCollection();
foreach ($products as $product) {
    if (!$product->hasThumbnail()) $product->setThumbnail($product->getSmallImage());
    $product->save();
}

Not saving thumbnail 🙁

Also tried this:

$value=$product->getData('small_image');
if ($value) {
    Mage::getSingleton('catalog/product_action')
            ->updateAttributes(array($product->getId()), 
                array(
                    'image'=>$value,
                    'small_image'=>$value,
                    'thumbnail'=>$value,
                    ), 
                0);  // 0 specifies the Default
    }

But when I try to update each product in loop Getting this error:
Mage registry key "_singleton/" already exists error

Best Answer

<?php 
require 'app/Mage.php';
Mage::app();
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
foreach ($products as $product) {
    if (!$product->hasImage()) continue;
    if (!$product->hasThumbnail()) {
        $product->setThumbnail($product->getSmallImage());
    }
$product->save();
}
?
Related Topic