Google+

Pages

Sunday, July 6, 2014

Magento: Set page layout on specific pages programmatically

If you want to set page layout on specific pages programmatically; for example you need to change layout from 1column.phtml to 2columns-left.phtml in some condition or so, then you need to create a simple module for it.

Steps to do so are given below:


Under app/etc/modules folder create your module's definition file (Package_Module.xml) and put this code in it:

<?xml version="1.0"?>
<config>
    <modules>
        <Package_Module>
            <codePool>local</codePool>
            <active>true</active>
        </Package_Module>
    </modules>
</config>
 
Now create config.xml file under 
app/code/local/Your/Module/etc folder and put this code in it:
 
<?xml version="1.0"?>
<config>
    <modules>
        <Package_Module>
            <version>0.1.0</version>
        </Package_Module>
    </modules> 
    <global> 
        <models>
            <module>
                <class>Package_Module_Model</class>
            </module>
        </models>
        <events> 
            <controller_action_layout_generate_blocks_after>
                <observers>
                    <any_unique_name>
                        <type>singleton</type>
                        <class>Module/Observer</class>
                        <method>controllerActionLayoutGenerateBlocksAfter</method>
                    </any_unique_name>
                </observers>
            </controller_action_layout_generate_blocks_after>
        </events>
    </global>
</config>
 
Now create Observer.php under app/code/local/Your/Module/Model folder and put this 
code in it:
 
<?php
class Package_Module_Model_Observer
{
    public function controllerActionLayoutGenerateBlocksAfter ($observer)
    {
        $controller = $observer->getAction();

        if ($controller->getFullActionName() == 'catalog_product_view') {
            $layout = $controller->getLayout();
            $rootBlock = $layout->getBlock('root');

            if (Mage::getSingleton('customer/session')->isLoggedIn()) {
                $rootBlock->setTemplate('page/1-column.html');
            } else {
                $rootBlock->setTemplate('page/2-columns.html');
            }
        }
    }
}
 
That's it. Cheers.. :) 

Friday, May 30, 2014

Magento: admin/admin in path in magento admin

Are you facing problem of getting 'admin/admin/' instead of 'admin/' in Magento admin URLs. Don't worry..

Here are some easy steps to get your admin URLs back to original.
  1. Check the values in /magentofolder/app/etc/local.xml and ensure all is good.
  2. Log in and check the values at System > configuration > Web > Unsecure URL (and Secure URL) - make sure they are good (they should be, otherwise you’d not be able to log in very easily.
  3. Go to System > configuration > Advanced > Admin and set the value of use custom admin url to 'No' and remove any values, if any, in the URL box underneath it. Then save config.
  4. If all these settings are correct, and you’re seeing admin/admin, then check:
System > Configuration > General > Web > URL options > Add store code to URL

There you must have set its value 'Yes'.

What this does is on the front end it includes the store code (actually store view code) to the URL for mutli-store setups, so that you can access a store like this : http://url/index.php/storecode1/ or http://url/index.php/storecode2/ ... etc.

But unfortunately it also does it for the admin (which has store code admin) - therefore, the path to your admin is now admin/admin - the first being the store code, the second being the path to serve the application. And so, some extensions that don’t use dynamic admin URL path won’t work - probably you’ll get a 404 where you expect your content to be in the main body of the page.

Enabling the second option in that admin (System > configuration > General > Web > URL options), i.e. "Redirect to Base URL if requested URL doesn’t match it" should fix all the problem.

If it still does not fix your problem then the last option to fix it to turn 'No' for 'Add Store Code to URLs'  option.

Hope this will help.. :)

Wednesday, May 28, 2014

How to reset admin password in Magento

If you have forgot your admin login password in Magento, there is an easy way to reset it.
Let's first find all users in 'admin_user' table.To do so, either you can view 'admin_user' table contents or fire below query:

SELECT * FROM admin_user;

Now to change password, you need to fire below query:

UPDATE `admin_user` SET `password` = CONCAT(MD5('qXpassword'), ':qX') WHERE `username` = 'USERNAME';

where 'qX' is salt value for encryption and it can be any other string and 
'USERNAME' is the desired user name for which you want to reset password.

For example:

user name is 'admin' for which you want to reset password.

Suppose after reset you want to set password 123456 and salt value you like is 'mK', 
then query to be fired will be:

UPDATE admin_user SET password=CONCAT(MD5('mK123456'), ':mK') WHERE username='admin';

Hope it will help. :)