Tuesday 18 February 2014

How to get child category in magento

$collections= Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('is_active',1)->addAttributeToFilter('parent_id',5)->addOrderField('position');

How to get all category in magento


<?php $category_model = Mage::getModel('catalog/category')->load($categoryid);
       $all_child_categories = $category_model->getResource()->getAllChildren($category_model );
   
 foreach ($all_child_categories as $child_id){
}

//===============OR=====================

$categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*')->addIsActiveFilter();
     foreach($categories as $ubcat){
 
 
   $catId=$ubcat->getId();
 
     }
     ?>

How to get product images on magento


<?$_images = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages();?>
<?if($_images){?>   
   <?$i=0; foreach($_images as $_image){ $i++;?>
      <a href="#"><img src="<?=$this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize(200, 130); ?>" width="200" height="130" alt="<?=$this->htmlEscape($_image->getLabel());?>" title="<?=$this->htmlEscape($_image->getLabel());?>" /></a>    
   <?}?>
<?}?>

Wednesday 12 February 2014

Create category attribute select option



<?php  require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$attribute = array(
'type' => 'int',
'label'=> 'Featured Category',
'input' => 'select',
'source' => 'eav/entity_attribute_source_boolean',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => 0,
'group' => "General Information"
);
$installer->addAttribute('catalog_category', 'featured_category', $attribute);
$installer->endSetup();
?>