Magento: Running script out side Magento Folder and Updating Project Database

Magento: Running script out side Magento Folder and Updating Project Database

Place this script ‘image.php’ out side magento folder and run this with http://yoursite/image.php, this will update all product images if there is no small or thumbnail image.
It will make first image as thumb and small image.

An example to run script out side magento folder.

require ‘app/Mage.php’;
Mage::app();

$products = Mage::getModel(‘catalog/product’)->getCollection()->addAttributeToSelect(‘*’);
foreach ($products as $product) {
 if (!$product->hasImage()) continue;
 if (!$product->hasSmallImage()) $product->setSmallImage($product->getImage());
 if (!$product->hasThumbnail()) $product->setThumbnail($product->getImage());
 $product->save();
}

Pin It on Pinterest

Share This