2

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

1
<?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();
}
?
  • Getting error : Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 74 bytes) in D:\wamp\www\sdwheel\lib\Zend\Db\Statement\Pdo.php on line 290 – Sarfaraz bheda Aug 29 '16 at 11:54
  • Increase memory size in .htaccess file to : php_value memory_limit 1024M – Ashish Jagnani Aug 29 '16 at 11:57
  • In wampserver php.ini says max_execution_time = 500000 – Sarfaraz bheda Aug 29 '16 at 11:57
  • The value is ` memory_limit = 1000M` – Sarfaraz bheda Aug 29 '16 at 11:59
  • May we its not able to load all product collection because you have lots of product. So in that case use limit in collection and only load those product which don't have thumbnail attribute set with filter condition – Ashish Jagnani Aug 29 '16 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.