Detect Home Page – Magento
Method 1 (For All Version of Magento):
if($this->getUrl('') == $this->getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true)))
{
// Home page
}
{
// Home page
}
if($this->getIsHomePage())
{
// Home page
}
{
// Home page
}
Detect Category Page – Magento
if (Mage::registry('current_category'))
{
// category page
}
{
// category page
}
if (Mage::registry('current_category'))
{
// Category Name
echo Mage::registry('current_category')->getName();
// Category ID
echo Mage::registry('current_category')->getId();
}
{
// Category Name
echo Mage::registry('current_category')->getName();
// Category ID
echo Mage::registry('current_category')->getId();
}
Detect CMS Page – Magento
if(Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms')
{
// CMS page
}
{
// CMS page
}
if(Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms')
{
echo Mage::getSingleton('cms/page')->getIdentifier();
}
{
echo Mage::getSingleton('cms/page')->getIdentifier();
}
Detect Product Detail Page – Magento
if(Mage::registry('current_product'))
{
// Product detail page
}
{
// Product detail page
}
Detect Configure Product Page – Magento
if(Mage::app()->getFrontController()->getRequest()->getRequestedActionName() == 'configure')
{
// Product Configuration page
}
{
// Product Configuration page
}
Detect Cart Page – Magento
$request = $this->getRequest();
$module = $request->getModuleName();
$controller = $request->getControllerName();
$action = $request->getActionName();
if($module == 'checkout' && $controller == 'cart' && $action == 'index')
{
//Cart Page
}
$module = $request->getModuleName();
$controller = $request->getControllerName();
$action = $request->getActionName();
if($module == 'checkout' && $controller == 'cart' && $action == 'index')
{
//Cart Page
}
No comments:
Post a Comment