Saturday, November 6, 2010

Magento Custom Category Listing Block

<?php
$cats = Mage::getModel('catalog/category')->load(2)->getChildren();
$catIds = explode(',',$cats);
?>
<ul>
<?php foreach($catIds as $catId): ?>
<li>
<?php
$category = Mage::getModel('catalog/category')->load($catId);
echo $category->getName();
$subCats = Mage::getModel('catalog/category')->load($category->getId())->getChildren();
$subCatIds = explode(',',$subCats);
?>
<?php if(count($subCatIds) > 1):?>
<ul>
<?php foreach($subCatIds as $subCat) :?>
<li>
<?php
$subCategory = Mage::getModel('catalog/category')->load($subCat);
echo $subCategory->getName();
?>
</li>
<?php endforeach;?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>


The XML Block Code:

<block type="catalog/navigation" name="catalog.category" template="catalog/navigation/category.phtml" />

Saturday, September 25, 2010

How to check current page is Homepage in magento

<?php if(Mage::getSingleton('cms/page')->getIdentifier() == 'home' && Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms') :
echo “Home Page”;
else:
echo “Not Home Page”;
endif;
?>

Sunday, August 29, 2010

Adding Products To The Home Page Of Magento

You will need to add some code to your home page in order to display all products you have specified as new. Go to CMS->Manage Pages and select the home page to edit.

Add this code to underneath your page title.

{{block type=”catalog/product_new” name=”home.catalog.product.new” alias=”product_homepage” template=”catalog/product/new.phtml”}}

Go check your homepage and your product will be displayed there.
For more please visit the below link.
How To - Display products on home page

Sunday, July 25, 2010

Code to get store's skin to create a full url

$this->getSkinUrl('images/img_name.jpg')

OR

<img scr="{{skin url=images/img_name.jpg}}” width="220" height="180"/>

Sunday, June 6, 2010

Magento Admin Login not working on Localhost.

Here is the simple fix to override this problem.
This is for Magento v1.3.2.4 :

Open this file,
app/code/core/Mage/Core/Model/Session/Abstract/Varien.php
and find the    session_set_cookie_params(line-78) and replace your code with this ;

session_set_cookie_params(
$this->getCookie()->getLifetime(),
$this->getCookie()->getPath()
//$this->getCookie()->getDomain(),
//$this->getCookie()->isSecure(),
//$this->getCookie()->getHttponly()  

also remove the comma from end of getPath().

This is for Magento v1.4.0.1 :Open up Varien.php at magentoappcodecoreMageCoreModelSessionAbstract and find the following snippet starting at line 77:

// session cookie params
$cookieParams = array(
'lifetime' => $cookie->getLifetime(),
'path' => $cookie->getPath(),
'domain' => $cookie->getConfigDomain(),
'secure' => $cookie->isSecure(),
'httponly' => $cookie->getHttponly()
);

if (!$cookieParams['httponly']) {
unset($cookieParams['httponly']);
if (!$cookieParams['secure']) {
unset($cookieParams['secure']);
if (!$cookieParams['domain']) {
unset($cookieParams['domain']);
}
}
}

if (isset($cookieParams['domain'])) {
$cookieParams['domain'] = $cookie->getDomain();
}
  Now comment out the relevant parts like so:// session cookie params
$cookieParams = array(
'lifetime' => $cookie->getLifetime(),
'path' => $cookie->getPath(),
'domain' => $cookie->getConfigDomain(),
'secure' => $cookie->isSecure(),
'httponly' => $cookie->getHttponly()
);

/* if (!$cookieParams['httponly']) {
unset($cookieParams['httponly']);
if (!$cookieParams['secure']) {
unset($cookieParams['secure']);
if (!$cookieParams['domain']) {
unset($cookieParams['domain']);
}
}
}

if (isset($cookieParams['domain'])) {
$cookieParams['domain'] = $cookie->getDomain();
}*/