Last active
March 15, 2018 15:45
-
-
Save 0-Sony/35587b02cafa351fbed1601ad0b5087a to your computer and use it in GitHub Desktop.
Magento : Generic Method to Get Page Type using for Tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Namespace_MyModule_myClass extends Mage_Core_Template | |
| /** | |
| * Get Page Type | |
| * @return string | |
| */ | |
| public function getPageType() | |
| { | |
| $fullActionName = Mage::app()->getFrontController()->getAction()->getFullActionName(); | |
| /** @var Mage_Core_Helper_Url $urlHelper */ | |
| $urlHelper = Mage::helper('core/url'); | |
| $pageType = ''; | |
| if ($fullActionName == 'cms_index_index') { | |
| $pageType = 'homepage'; | |
| } elseif ($fullActionName == 'cms_page_view') { | |
| $currentUrl = $urlHelper->getCurrentUrl(); | |
| $urlkey = str_replace(Mage::getBaseUrl(), '', $currentUrl); | |
| $pageData = Mage::getModel('cms/page')->load($urlkey, 'identifier'); | |
| $pageType = $pageData->getTitle(); | |
| } elseif ($fullActionName == 'contacts_index_index') { | |
| $pageType = 'contacts'; | |
| } elseif ($fullActionName == 'catalog_category_view') { | |
| $pageType = 'listing'; | |
| } elseif ($fullActionName == 'catalog_product_view') { | |
| $pageType = 'product'; | |
| } elseif ($fullActionName == 'catalogsearch_result_index') { | |
| $pageType = 'catalogsearch'; | |
| } elseif($fullActionName == 'checkout_cart_index'){ | |
| $pageType == 'cart'; | |
| } elseif($fullActionName == 'onepagecheckout_index_index' || $fullActionName == 'checkout_index_index'){ | |
| $pageType == 'checkout'; | |
| } elseif($fullActionName == 'onepagecheckout_index_success' || $fullActionName == 'checkout_index_success'){ | |
| $pageType = 'success'; | |
| } | |
| return $pageType; | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Namespace_MyModule_myClass extends Mage_Core_Template | |
| /** | |
| * Get Page Type | |
| * @return string | |
| */ | |
| public function getPageType() | |
| { | |
| $handles = $this->getLayout()->getUpdate()->getHandles(); | |
| $pageType = ''; | |
| $pages = [ | |
| 'cms_index_index' => 'hompage', | |
| 'cms_page_view' => $this->_getCmsPageTitle(), | |
| 'customer_account' => 'mon compte', | |
| 'contacts_index_index' => 'contacts', | |
| 'catalog_category_view' => 'categorie', | |
| 'catalog_product_view' => 'produit', | |
| 'catalogsearch_result_index' => 'recherche', | |
| 'checkout_cart_index' => 'panier', | |
| 'checkout_onepage_index' => 'tunnel' | |
| ]; | |
| foreach ($pages as $type => $pageName) { | |
| if (in_array($type, $handles)) { | |
| $pageType = $pageName; | |
| break; | |
| } | |
| } | |
| return $pageType; | |
| } | |
| /** | |
| * @return mixed | |
| */ | |
| private function _getCmsPageTitle() | |
| { | |
| return $this->getLayout()->getBlock('head')->getTitle(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment