Friday, 7 June 2013

How to get Current Page URL, Module, Controller and Action Name, CMS Page URL and Current Skin URL in Magento.

<?php
$currentUrl = $this->helper('core/url')->getCurrentUrl();  // Get Current Page URL

$request = $this->getRequest();
$module = $request->getModuleName();  // Get Current Module Name
$controller = $request->getControllerName();  // Get Current Controller Name
$action = $request->getActionName();  // Get Current Action Name

Mage::app()->getFrontController()->getRequest()->getModuleName();  //Get Current Module Name
Mage::getSingleton('cms/page')->getIdentifier();  // Get Current CMS page
Mage::app()->getFrontController()->getRequest()->getRouteName();  // Get Route Name
Mage::getSingleton('cms/page')->getIdentifier();  // Get Identifier Name

Mage::getDesign()->getSkinUrl(); // Get Current Skin URL
?>

Wednesday, 26 September 2012

Add New Custom Page Layout in Magento.


Hello Magento Developer,

Here is the Solution for adding New Custom Page Layout in Magento.
You have to create one Module for this Extra Custom Layout.

1. Create Your Module File called Home_Layout.xml in app/etc/modules

Insert the following code into the file:

<?xml version="1.0"?>
<config>
    <modules>
        <Home_Layout>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Page/>
            </depends>
        </Home_Layout>
    </modules>
</config>

2. Now create Config File of your Module called config.xml and put this file in the Following directory Structure.

app/code/local/Home/Layout/etc/config.xml

Insert the following code into the file:

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <global>
          <page>
               <layouts>
                    <home_layout module="page" translate="label">
                         <label>Home Layout</label>
<template>page/home-layout.phtml</template>
<layout_handle>page_home_layout</layout_handle>
</home_layout>
</layouts>
          </page>
     </global>
</config>

3. Now you have to create Template File of your Module called home-layout.phtml and put this file in the Following directory Structure.

app/design/frontend/default/YOUR_THEME/page/home-layout.phtml

Write Your Code Here... For Example

<h1><?php echo "New Custom Page Layout Successfully Created.";?></h1>

4. Finally go to CMS->Pages->Home Page->Design. You can see your New additional Custom Layout in dropdown.

Now Select "Home Layout" and Press Save Page.

Now clear Cache of your store and See the changes on Home Page.

Tuesday, 4 September 2012

Displaying Currency Symbol after Price in Magento.

Hello Magento Developers,

There is a one Trick for changing position of Currency Symbol from LEFT to RIGHT in Magento.

For that you have to do Minor changes in your Language File. Following is the Directory Structure of File.

=> root/lib/Zend/Locale/Data/en.xml (For English Language)

=> around line 2611 you can see following code.
<currencyFormat>
<pattern>¤#,##0.00;(¤#,##0.00)</pattern>
</currencyFormat>

=> Now Change above code with Following code.

  <currencyFormat>
<pattern>#,##0.00 ¤;(#,##0.00 ¤)</pattern>
</currencyFormat>

Note: The little square ( ¤ ) sets the currency symbol position after Price in magento.

=> Now clear Cache of your store and You can see changes.

Thanks,
Abhishek