Magento Quick Snippets

Cart Counter:

helper('checkout/cart')->getSummaryCount();  //get total items in cart
$total = $this->helper('checkout/cart')->getQuote()->getGrandTotal(); //get total price

if ($count == 0) {
   echo $this->__('(0 ITEMS)', $count);
}

if ($count == 1) {
   echo $this->__('(1 ITEM)', $count);
}

if ($count > 1) {
   echo $this->__('(%s ITMES)', $count);
}
?>

Create Block By XML:

  

Create block by PHP:

 getLayout()->createBlock('core/template')->setTemplate('page/html/feature-ads.phtml')->toHtml(); ?> 

Layout local.xml



    
        
        
            
            
        
 
        
        
            
            skin_csscss/styles.css
            skin_jsjs/functions.js
            
            skin_jsscripts/functions.js
            skin_csscss/styles.css
            
            jsscripts/functions.js
        
 
        
        
            
            
                header_cms_block
            
        
 
        
        
            
                
            
        
 
        
                           
                
                       
                
                
                 
           
         
                        
                        
                             
                           
              
                  
                   
            
    
 
    
    
    
 
    
    
    
 
    
    
        
        
            
                
            
        
    
 
    
    
    
 
    
    
    
 
    
    
    
 
    
    
        
        
            customer-account-page
        
    
 
    
    
    
 
    
    
    
 
    
    
        
        
            
            
        
    
 
    
    
    
 
    
    
    
 
    
    
    
 
    
    
    
 
    
    
    

Check if customer login or not:

if ( $this->helper('customer')->isLoggedIn() ) {
//loggedin
}

Debug layout:

var_dump(Mage::app()->getLayout()->getUpdate()->getHandles());

Get Product Attribute from id, without loading product

Mage::getResourceSingleton('catalog/product')
  ->getAttributeRawValue($productId, 'url_key', Mage::app()->getStore());

Posted

in

by

Tags: