Last active
August 6, 2020 13:05
-
-
Save victordit/1374438f5dc115de0e527221fbacacc7 to your computer and use it in GitHub Desktop.
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_once "app/Mage.php"; | |
umask(0); | |
// set current store to admin and turn on developer mode | |
Mage::app('admin'); | |
Mage::setIsDeveloperMode(true); | |
// load product collection | |
$productCollection=Mage::getResourceModel('catalog/product_collection'); | |
foreach($productCollection as $product){ | |
echo $product->getId(); | |
echo "<br/>"; | |
$MediaDir=Mage::getConfig()->getOptions()->getMediaDir(); | |
echo $MediaCatalogDir=$MediaDir .DS . 'catalog' . DS . 'product'; | |
echo "<br/>"; | |
$MediaGallery=Mage::getModel('catalog/product_attribute_media_api')->items($product->getId()); | |
echo "<pre>"; | |
print_r($MediaGallery); | |
echo "</pre>"; | |
foreach($MediaGallery as $eachImge){ | |
$MediaDir=Mage::getConfig()->getOptions()->getMediaDir(); | |
$MediaCatalogDir=$MediaDir .DS . 'catalog' . DS . 'product'; | |
$DirImagePath=str_replace("/",DS,$eachImge['file']); | |
$DirImagePath=$DirImagePath; | |
// remove file from server | |
$io = new Varien_Io_File(); | |
$io->rm($MediaCatalogDir.$DirImagePath); | |
// remove product image association in db | |
$remove=Mage::getModel('catalog/product_attribute_media_api')->remove($product->getId(),$eachImge['file']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment