Created
June 13, 2014 12:54
-
-
Save gibbs/dca0624930c78a3d40a3 to your computer and use it in GitHub Desktop.
Magento - Set all product images to small, base and thumbnail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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(); | |
} |
I used a variation of this gist that worked on Magento 1.9
I used this to get the products
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->setPageSize(5000);
And this to get the images
$gallery_images = Mage::getModel('catalog/product')->load($product->getId())->getMediaGalleryImages();
$path = $gallery_images->toArray()["items"][0]["file"];
Other than that, the setting of the product images works
if (!$product->hasSmallImage()) $product->setSmallImage($path);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is wonderful!
Is there any way to make it work in groups for bigger stores, to avoid timeouts?