Monday, 16 March 2015

Detect Home Page – Magento

Detect Home Page – Magento

Method 1 (For All Version of Magento):
if($this->getUrl('') == $this->getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true)))
{
  // Home page
}
Method 2 (For Magento 1.5 and Above):
if($this->getIsHomePage())
{
  // Home page
}

Detect Category Page – Magento

if (Mage::registry('current_category'))
{
  // category page
}
Now see how we can get ID and Name of the category if current page is category page.
if (Mage::registry('current_category'))
{
  // 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
}
Get CMS page name if current one is the CMS page.
if(Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms')
{
  echo Mage::getSingleton('cms/page')->getIdentifier();
}

Detect Product Detail Page – Magento

if(Mage::registry('current_product'))
{
  // Product detail page
}

Detect Configure Product Page – Magento

if(Mage::app()->getFrontController()->getRequest()->getRequestedActionName() == 'configure')
{
  // 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
 }

No comments:

Post a Comment