Simple Magento code

It may help, for you doubt

1. List all Categories :

<?php
$obj = new Mage_Catalog_Block_Navigation();
$store_cats = $obj->getStoreCategories();
$current_cat = $obj->getCurrentCategory();
$current_cat = (is_object($current_cat) ? $current_cat->getName() : ”);
foreach ($store_cats as $cat)
{
if ($cat->getName() == $current_cat) {

echo ‘<li class=”current”><a href=”‘.$this->getCategoryUrl($cat).'”>’.$cat->getName().”</a>\n<ul>\n”;

foreach ($obj->getCurrentChildCategories() as $subcat)
{
echo ‘<li><a href=”‘.$this->getCategoryUrl($subcat).'”>’.$subcat->getName().”</a></li>\n”;
}
echo “</ul>\n</li>\n”;
}
else
{
echo ‘<li><a href=”‘.$this->getCategoryUrl($cat).'”>’.$cat->getName().”</a></li>\n”;
}
}
?>

2. List All Product Image :

<?php
require_once (‘/app/Mage.php’);
$cProduct = Mage::getModel(“catalog/product”);
for($v=0;$v<=5;$v++)
{
$cProduct->load($v);
$imageLink= $cProduct->getImageUrl() ;
?>
<img src=”<?php echo $imageLink;?>” height=”80″ width=”100″/>
<!– image End here –>
<?php
}
?>

3. Disable Postcode ZipCode Validation :

All these values are defined in the respective shipping modules by overwriting the default return value.
In /app/code/core/Mage/Shipping/Model/Carrier/Abstract.php we find the default

4. How to get the customer’s shipping address in Magento?

$customerAddressId = Mage::getSingleton(‘customer/session’)->getCustomer()->getDefaultShipping();
if ($customerAddressId)
{
$address = Mage::getModel(‘customer/address’)->load($customerAddressId);
}

5. How to set session and get session in Magento?

Mage::getSingleton(‘core/session’)->setYourVariable(‘data’);
Mage::getSingleton(‘core/session’)->getYourVariable();

6. How to Check if customer is logged in or not in Magento?

<?php
if(!Mage::getSingleton(‘customer/session’)->isLoggedIn())
{
Echo “Log Out”;
}
else {
echo “Log In”;
} ?>