Monday, 24 October 2016

Magento 2

Magengto 2

While working with Magento 2, i come up with some questions. Basically i tried to compare Magento 1. X with Mgento 2.
I think below question might be helpfull to understand Magento folder structure.

Question : What is Bin Folder?

Answer :

- Consist of  CLI programe file
- Consist .htaccess


Question : Where core files stored in Magento 2?

Ans : Can be find at,

\vendor\magento


Question : Where skin, error, js and media file store in Magento 2?
Ans : In Pub folder.


Question : What is Dev Folder?

Answer :

- It Consist Shell folder.


Question : Which folders removed in Magento 2?


Answer :Below are the folders removed in Magento 2,

- downloader
- includes
- Phpinfo


Question :  Where we can find Database connection settings?

Answer: We can find Database connection settings env.php. Below is the location,
app/etc/env.php


'db' =>
  array (
             'table_prefix' => '',
              'connection' =>
   
       array (
                 'default' =>  
                             array (
                                      'host' => 'localhost',
 
                                     'dbname' => '',
   
                                      'username' => '',
   
                                      'password' => '',
     
                                      'active' => '',
   
                                      ),
 
                   ),

                ),

Thursday, 6 October 2016

'Service Temporarily Unavailable' on Magento site.

Magento have build mechanism when installing the module. Well, If at the same time of installation any activity runs it show the 'Service Temporarily Unavailable' message at front.
Basically Magento sets the maintenance.flag . Normally Magento create maintenance.flag at the root of the project folder. This avoid the run time error for users.

To return to normal :

You can simply remove the maintenance. Then your store will back to normal..

How to get base url of for multi-store ( Js, Media, skin, web etc.)


First you need to know your store id. To get the store id you can use,

$storeId = Mage::app()->getStore()->getStoreId();

Then, you can easily get the  store, Js, Media, skin, web etc.  Here is the full list,


Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

Getting base url of specific store view in Magento.

If you done with multistore then its some time require to get the store url. So you can simply use below code to achive it.
Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);

$installer = $this; in install scripts

Installer script funs with context of setup resource class,

Mage_Core_Model_Resource_Setup

So it menace $this is reference to object instantiated from this class. While its not necessary to have this alias, but its nothing but the convention. It's always better to follow best practices with for convention. 

Why Magento PHP files done have closing PHP tags?

Working with Magento you can oberve that controller, module, installer, helper PHP files don't include PHP ending tags. The reson behind is,

1) PHP interpreter accept the missing closing tag in PHP.
2) It avoid the white space when you try to get response from code.

Thursday, 29 September 2016

Difference between “Flush Magento Cache” and “Flush Cache Storage”

Flush Magento Cache

It removes the cache entries which are known by Magento itself.

Flush Cache Storage

It clears everything, including entries made by other supporting or external Caches systems. Normally the location is "var/cache/".

How to write Magento session messages.

Many time we require to send the messages within your. We can do it through core session.
Below is useful core session message we can send.

1) Send notice message.
Mage::getSingleton('core/session')->addNotice("Need attension");

2) Send success message.

Mage::getSingleton('core/session')->addSuccess("Its done!");

3) Send error message.

Mage::getSingleton('core/session')->addError("Error is there!");

Wednesday, 28 September 2016

How to redirect to controller with parameters in Magento.



How to redirect to controller with Parameters?

Many time we require to redirect to controller with some parameters and need to GET parameters at business module.

Below is the example to do it:

$this->_redirect('yourmodule/controller/action', array('First Parameter'=>'1','Second Parameter'=>'2'));

This will helpful, when you need more than one buttons on same page and want to implement the different logic on different clicks.

Monday, 12 September 2016

Rearrange form fields in the Magento admin panel?

Rearrange form fields in the Magento admin panel?

Some time it require to Rearrange form custom fields in the Magento. This can be achieve while running the custom script as below. Considering we are doing this for customer address field.


$this->addAttribute('customer_address', 'your_custom_field', array(
'type' => 'varchar',
'input' => 'text',
'label' => 'your_custom_field',
'global' => 1,
'visible' => 1,
'required' => 0,
'user_defined' => 0,
'visible_on_front' => 1,
'position' => 60 ));

Note: Recommended, Please keep database back-up while running the scripts.

Please leave your comments, if you find this post is useful.

Thursday, 1 September 2016

Adding Translations in Magento JavaScript.


Some time you require to add translation through Javascript and you don't have any option to add it via your template.  Below is the code for do it.

<script type="text/javascript">
Translator.add('Your translation.','<?php echo Mage::helper('yourmodule')->__('Your translation.')?>');
</script>

Please leave your comments, if you find this post is useful.

Adding Translations in Magento JavaScript.


Some time you require to add translation through Javascript and you don't have any option to add it via your template.  Below is the code for do it.

<script type="text/javascript">
Translator.add('Your translation.','<?php echo Mage::helper('yourmodule')->__('Your translation.')?>');
</script>

Please leave your comments, if you find this post is useful.

Thursday, 14 April 2016

Diffrent Order status and how to change Order status.

Order status

Mage_Sales_Model_Order::STATE_NEW
Mage_Sales_Model_Order::STATE_COMPLETE
Mage_Sales_Model_Order::STATE_PROCESSING
Mage_Sales_Model_Order::STATE_PENDING_PAYMENT
Mage_Sales_Model_Order::STATE_HOLDED
Mage_Sales_Model_Order::STATE_CANCELED
Mage_Sales_Model_Order::STATE_CLOSED

Some time we need to explicitly update the order status. We can change or update the order status as below,

$yourOrder->setState(Mage_Sales_Model_Order::STATE_HOLDED, true);
$yourOrder->save();

It's always good practice to take database backup while doing such operations.

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.