Monday, May 14, 2012

Category wise New product

If you want to show new product Category wise then go to the app\code\core\Mage\Catalog\Block\Product\New.php add
if($categoryId = Mage::app()->getRequest()->getParam('category_id')){           
        $category = Mage::getModel('catalog/category')->load($categoryId);
        $collection->addCategoryFilter($category);
        }          
before
        $this->setProductCollection($collection);

also open app\design\frontend\base\default\template\catalog\product\new.phtml

<?php if(Mage::app()->getRequest()->getParam('category_id')==''){ ?>
<h2 class="subtitle"><?php echo $this->__('New Arrivals') ?></h2>
<?php
    $category_model = Mage::getModel('catalog/category'); //get category model
    $_category = $category_model->load(2); //$categoryid for which the child categories to be found    
    $all_child_categories = $category_model->getResource()->getAllChildren($_category);
   
    foreach($all_child_categories as $category)
        {
            if($category!=2){
                $cur_category = Mage::getModel('catalog/category')->load($category);
                if($cur_category->getIsActive()){  ?>
                    <a href="<?php echo $this->getBaseUrl('all-new-arrival').'all-new-arrival/?category_id='.$category; ?>"><img src="<?php echo $cur_category->getImageUrl(); ?>" /><div><?php echo $cur_category->getName(); ?></div></a>                   
            <?php    }
            }
        }
?>   
<?php }else{  ?>
before
<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
and close the bracket end of the page.

No comments:

Post a Comment