Skip to content

Instantly share code, notes, and snippets.

@aaronlifton3
Created June 24, 2010 04:16
Show Gist options
  • Save aaronlifton3/450973 to your computer and use it in GitHub Desktop.
Save aaronlifton3/450973 to your computer and use it in GitHub Desktop.
Programmatically setting images as thumbnails in Magento
<?php
require_once 'app/Mage.php';
Mage::app();
mysql_connect(localhost, DATABASE_USER, DATABASE_PASSWORD);
mysql_select_db(DATABASE_NAME) or die("Unable to select database");
$result = mysql_query("SELECT * FROM `catalog_product_entity_varchar` WHERE attribute_id in (74,75,76) AND value='no_selection'");
while ($row = mysql_fetch_array($result)) {
$id = $row["entity_id"];
$product = Mage::getModel("catalog/product")->load($id);
$mediaGallery = $product->getMediaGallery();
if ($mediaGallery["images"][0]["file"] != '' || $mediaGallery["images"][0]["file"] != NULL) {
$path = $mediaGallery["images"][0]["file"];
$update_result = mysql_query("UPDATE `catalog_product_entity_varchar` SET VALUE='".$path."' WHERE attribute_id in (74,75,76) and entity_id=".$id);
echo "set images for product ".$id."<br />";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment