Monday, 29 February 2016

Overidding magento controller.



Its quite different to override Magento controller than overriding Models, helpers, and blocks. Here we will see how we can override the Magento controller. Here I am taking wishlist model of Magento as an example,

1) Enable module: Enable your module configuration, at below path,

Path:  \app\etc\modules\Custom_Module.xml

<?xml version="1.0"?>

<config>

  <modules>

    <Custom_Module>

      <active>true</active>

      <codePool>local</codePool>

      <version>0.1.0</version>

    </Custom_Module>

  </modules>

</config>

2) Override the controller: you need to include require once in the controller file which you want to override, Please create controller file in below path,

Path:  \app\code\local\Custom\Module\controllers\Wishlist\ IndexController.php

<?php

require_once "Mage/Wishlist/controllers/IndexController.php";  


class Custom_Module_Wishlist_IndexController extends Mage_Wishlist_IndexController{


// your logic here


}

  
3) Module configuration: Now define the module configuration in below path,

Path: app\code\local\Custom\Module\etc\ config.php

<?xml version="1.0"?>

<config>

  <modules>

    <Custom_Module>

      <version>0.1.0</version>

    </Custom_Module>

  </modules>

  <frontend>

    <routers>

      <module>

        <use>standard</use>

          <args>

            <module>Custom_Module</module>

            <frontName>module</frontName>

          </args>

      </module>

    </routers>

  </frontend>

  <global>

                                <rewrite>       

            <custom_module_wishlist_indexcontroller>

                <from><![CDATA[#^/wishlist/index/#]]></from> <!-- Mage_Wishlist_IndexController  -->

                <to>/module/wishlist_index/</to> <!-- Custom_Module_Wishlist_IndexController  -->

            </custom_module_wishlist_indexcontroller>

                                </rewrite>

    <helpers>

      <module>

        <class>Custom_Module_Helper</class>

      </module>

    </helpers>

  </global>

  <admin>

                <routers>

                  <module>

                    <use>admin</use>

                                <args>

                                  <module>Custom_Module</module>

                                  <frontName>admin_module</frontName>

                                </args>

                  </module>

                </routers>

  </admin>

</config>


4) Setting up helper (If you wish to use):  You can also set the helper class as below,

\app\code\local\Custom\Module\Helper\ Data.php

<?php

class Custom_Module_Helper_Data extends Mage_Core_Helper_Abstract

{


// your custom logic


}

That set!!
Now we are ready to use the wishlist controller core features.

Simple debugging with Magento (Using default and custom log files)


Several time developers need debugging to solve issues, in this post we will see how we can debug easily in Magento.

1) Default logs :  

If you want to check some data to confirm the values in it. You can simply use below code,

Mage::log("Check my data");

Now question is, where I can find the result of above code?

Simple: You can get the result at var/log/ folder and files will be,

 - exception.log
 - system.log

2) Custom log files creation:

Moving ahead you can also write your own custom logs for more advance debugging as below,

Use below statement,

Mage::log("Check your data", null, yourlogfile.log);

Now same question after declaration of above code where I can find the results?

Simple, you can find the result in directory var/log/

Now, I hope it will help you to debug your code or any Magento features. 




Getting current module details in Magento

1)  Getting current module name :

=> Mage::app()->getRequest()->getModuleName();

2)  Getting current controller name :

=> Mage::app()->getRequest()->getControllerName();

Magento Useful paths

Getting Magento path :

1) Mage::getBaseDir();
 Return output : /var/www/html/yourwebsite

2) Mage::getBaseDir('app')
 Return output : /var/www/html/yourwebsite/app

3) Mage::getBaseDir('media')
 Return output : /var/www/html/yourwebsite/media

4) Mage::getBaseUrl('js')
Return output : http://yourwebsite.com/js/

5) Mage::getBaseUrl('skin')
Return output : http://yourwebsite.com/skin/

Wednesday, 16 December 2015

Improve Magento speed and performance




Improve Magento speed and performance

Due to large amount of catalog data, heavy third party customization, Large size images, database
sometime Magento shop owner face the speed issue.
There are lots of ways to optimize it.

1) Moving Magento to good Hosting environment (dedicated server.).
2) Enable Gzip Compression.
3) For images and static content we can use Content Delivery Network (CDN) for parallel transfer of static content.
4) Use Varnish caching.
5) Minify Css.
6) Minimize JavaScript.
7) Disable modules, extension which are not in use.
8) Enable  Magento Caches
9) Combine Js and Css files.
10) Try some third party extensions to improve performance.

Thursday, 26 November 2015

Solving CMS blocks issue after upgrade



After upgrade to 1.9.2.2  my static blocks were vanished. After some research I found that we need to allow our blocks from, 


System -> Permissions -> Blocks



If you wish to enable the cms/block type, then simply add new entry to Permissions -> Blocks and set it to allowed.

Tuesday, 24 November 2015

Customer registration not working in Magento

Some time it happen that after migration or upgrade of Magento, Registration not work.

Solution is :

Add the below code to your theme register.phtml file,


<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />

Refresh cache and try again.