মঙ্গলবার, ২৯ মে, ২০১২

Showing Magento Static Block

Here is the code for showing magento static block. just add the line where you need to output the content of static block.

in phtml:
<?php 

  echo $this->getLayout()->createBlock('cms/block')->setBlockId('your-block-identifier')->toHtml();
?> 
in editor:
{{block type="cms/block" name="your-block-name" block_id="your-block-dentifier"}}

শুক্রবার, ১৮ মে, ২০১২

Get Magento Bestsellers Products list

sometimes we need to show bestselling products. here is a piece of code to get magento bestselling products easily

<?php
    $collection = Mage::getResourceModel('sales/report_bestsellers_collection')
                         ->setModel('catalog/product')
                         ->addStoreFilter(Mage::app()->getStore()->getId())//if you want the bestsellers for a specific store view. if you want global values remove this
                         ->setPageSize(5)//se there the number of products you want returned
                         ->setCurPage(1);
     foreach ($collection as $_product){
      $realProduct = Mage::getModel('catalog/product')->load($_product->getProductId());
      //do something with $realProduct;
     }
?>

Get Categories as Admin showing

Sometimes we need magento categories like its hierarchy as admin category panel showing. here is the code. hope that will help you also....

<?php
    $categories = Mage::getModel('catalog/category')->load('category_id')->getChildrenCategories();
     foreach($categories as $category){
              echo $category->getName(); 
              echo $category->getData('your_custom_attr_identifier');
    }            
?>

বৃহস্পতিবার, ১৭ মে, ২০১২

Get Magento Categories programatically

It saves my life many times whenever i need category listing with filter with some attributes.

    $categories = Mage::getModel('catalog/category')->getCollection()
                  ->addAttributeToSelect('name')
                  ->addAttributeToSelect('url_key')
                  ->addAttributeToSelect('my_attribute')
                  ->setLoadProductCount(true)
                  ->addAttributeToFilter('is_active',array('eq'=>true))
                  ->load();
   print_r($categories->getData()); //prints as an array