Magento Coding Solutions

program to delete Products Image by Category Magento

Step 1:
create a .php file "deleteProductImage.php" on root directory

<?php
require_once "app/Mage.php";
umask(0);
Mage::app('admin');
Mage::setIsDeveloperMode(true);
echo "<pre>";
if(!empty($_REQUEST['catId'])){
$categoryId=$_REQUEST['catId'];
}else{
echo "please Pass CategoryId!";
exit;
}

$limit=1000;
$start=0;
if(!empty($_REQUEST['start'])){
$start=$_REQUEST['start'];
}
if(!empty($_REQUEST['limit'])){
$limit=$_REQUEST['limit'];
}

$productCollection = Mage::getModel('catalog/category')
                    ->load($categoryId)
                    ->getProductCollection();
$productCollection->getSelect()->limit($limit,$start);



/* print_r($collection);
die; */
/*  ->load($categoryId)
                    ->getProductCollection(); */
foreach($productCollection as $product){
//print_r($product);
/* echo $product->getId();
echo "---</br>"; */
//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>"; */
if(count($MediaGallery)>0){

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 Dir

$io     = new Varien_Io_File();
$io->rm($MediaCatalogDir.$DirImagePath);

$remove=Mage::getModel('catalog/product_attribute_media_api')->remove($product->getId(),$eachImge['file']);
}
}else{
echo $product->getSku();
echo "</br>";

}


}
?>

Step 2:
Calling form url as
abc.com/deleteProductImage.php?catId=52limit=100start=0

Note: abc.com : your website.
          catId : pass category Id
         limit: how many product you want to delete.
         start : delete from product.




Magento. Listing Sub-Categories On A Category Page

Step 1 .
 create a "Static Block"
 and put in Content area below code.
{{block type="core/template" template="catalog/category/sub.phtml"}}

  



Step 2.
create "sub.phtml" file in  "/your template/catalog/category/sub.phtml"
 <div class="category-products">

<ul class="products-grid">
<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'thumbnail'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($category->getChildren());
$catDat =explode(',',$category->getChildren());
if(count($catDat)>0){
$categorycount = 0;
foreach($catDat as $catId){
$_category=Mage::getModel('catalog/category')->load($catId);

if($_category->getIsActive()){

if ($categorycount == 0){
$class = "first";
}elseif ($categorycount == 4){
$class = "last";
}else{
$class = "";
}
?>

<li class="item <?=$class?> catitm" align="center">
<div class="itemimg"><?php //echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>
<a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><img src="<?php  echo $_category->getImageUrl(); ?>" alt="<?php echo $this->htmlEscape($_category->getName()) ?>"     style="width: 425px !important;height: 425px;"/></a>
</div>
<h3><a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?></a></h3>
</li>

<?php

if($categorycount == 4){
$categorycount = 0;
echo "</ul>\n\n<ul class=\"products-grid\">";
}else{
$categorycount++;
}


}


}

}?>

</ul>

</div>
Output is :