Friday, August 15

How to Speed up Magento E-Commerce Store


Speed up the Magento store is always the challenging one. Everyone know to set the configuration in magento backend to optimize the site. apart from that we need to follow the below Hosting Environments and some other general tips.

First we should host the site in Dedicated server
Host the site in your customer country
Go to Mysql Admin Manager and Repair all the tables and Optimize the table
Only Install necessary Apache modules
use apache mod_expires and be sure to set how long the files should be cached.
Enable Gzip Compression in your htaccess file
Use Content Delivery Network(CDN) for a static content. like css,js,images
Please try to avoid external javascript and Iframe. Because every DNS lookup takes extra time.
Enable Apache KeepAlives.
Must Enable the Compilation mode in your Magento admin
Minimize the http redirects
Make your output should be W3C validated. because Errors may slowdown the browser
Turn off your Web server logs, it reduces the disk writes.
Try to Update the magento to latest version.
Increase the Query cache size in your Mysql Server
Set php_value_memory_limit to 128M in your php configuration to ensure we don't run out of memory.
Use Different server for Magento Application and MySQL.
Use Load Balancer to avoid the down time when more number of hits in the site.
If your site heavily crawled by the search engines, then you can tweak your robots.txt.
Ref: http://www.byte.nl/blog/magento-robots-txt/
Minimize the js and css files
specify the image dimensions for your images
try to Implement anyone of the cache like APC,Varnish,etc...
try to go with some other third party booster module like AITOC Magento Booster, Nitrogento



Thursday, June 19

Top 5 Issues Affecting Mangento Performance

Below are Most common Top 5 Issues, which causes 84% performance Issues. Most of the issues are due to inefficient operations, memory misuse, redundant or useless Looping.

1.    Calculating the size of an array on each iteration of a loop
2.    SQL queries inside a loop
3.    Loading the same model multiple times
4.    Redundant data set utilization
5.    Inefficient memory utilization

Reference : http://info.magento.com/rs/magentocommerce/images/Conquer_the_5_Most_Common_Magento_Coding_Issues_to_Optimize_Your_Site_for_Performance.pdf

Sunday, June 8

Magento Performance Optimization - A Complete Overview



Optimizing the magento speed is always the challenging one. In this article we will go through some of the steps to fine tune your server to allow magento to run more quickly.

1. Apache mod_expires
Whenever the user visits the site , always the web browser keep the cache of the web pages. All the web pages should have content expiry header that tells the browser when the cache will expires. If the header is not set properly always the page will request the content from the source with every page hit. in order to ensure magento set correct content expiry header, we need to add the following block of code in htaccess file.

ExpiresActive On
ExpiresDefault "access plus 1 month"

2. Apache KeepAlive
Apache KeepAlive functionality is used to allow the TCP connection between client and server  to remain open connection to allow multiple request to be served over the same connection. this can be used to decrease the page load time on web pages especially with lots of images, since it removes the over head of having multiple connections opened. to use this functionalities, edit the /etc/apache2/apache2.conf  and find keep alive entries and enabled as follows. 

KeepAlive On
KeepAliveTimeout 2

the timeout parameter is unit of seconds.   

3. GZip Compression
Web pages can be compressed using Gzip between client and server, reducing the amount of data that needs to be transferred. even though the act of compressing and decompressing adds a performance overhead, there is a net gain in reducing the traffic for large pages. to use GZip compression, enable the mod_deflate module in apache and add the following to the vhost for the site.

SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary

4. MySQL Tuner:
MySQL tuner is a perl script that allows to analysis your database and gives recommendation which variables you should adjust in my.cnf to increase the performance. this can really help to increase the performance without the expensive hardware changes. to install and run this script follow the command.

bash$ wget http://mysqltuner.com/mysqltuner.pl
bash$ perl mysqltuner.pl

In the next articles we will continue the below performance optimization technique.
  • MemCached
  • PHP APC
  • Database Session Storage
  • Query caching


Saturday, May 24

How to get Magento Admin Log Details


If you are running the magento store with multiple administrator, its very difficult to find who edited the product,category,sales or some other admin activities.

When I googled the module to find the admin log details, I didn't get any module. one day when i surfing in to magento admin panel, surprisingly I saw the admin log details.

with the help of admin log, we can easily discover which administrator logged and which page/category/product they visited and modification they made.we can view the detailed information on the history, date and time of the action made. so if something happened wrong in your store, we can find out who/what could caused the problem.

In Magento admin panel under system->admin action log we can see all the admin activities with detailed information.

Please refer the below screen-shot for reference.




Monday, May 7

How to add Order Profit column in Magento

here is the step by step tutorial to get order profit column in magento backend.

This column will show the profit gained per order (i.e, the difference between Cost and Selling Price)
1) Copy the app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php file to app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php, by maintaining the directory structure
2) There is a protected function _prepareColumns, kindly paste the below code inside it

//below code for showing profit
//start
 $this->addColumn('entity_id', array(
    'header' => Mage::helper('sales')->__('Profit'),
    'index' => 'entity_id',
    'type'  => 'currency',
    'currency' => 'order_currency_code',
    'renderer'  => new Mage_Adminhtml_Block_Sales_Order_Renderer_Profit() //for the value
));
//end

3) Create a file app/code/local/Mage/Adminhtml/Block/Sales/Order/Renderer/Profit.php (directory structure should be maintained).
Copy the following code as it is in it.
class Mage_Adminhtml_Block_Sales_Order_Renderer_Profit extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    public function render(Varien_Object $row)
    {
        $order_id = $row->getData($this->getColumn()->getIndex());
 
        if(!empty($order_id))
        {
            $sales_model = Mage::getModel('sales/order')->load($order_id);
            $subtotal = $sales_model->getSubtotal();//get order subtotal (without shipping)
            $items = $sales_model->getAllItems(); //get all order items
            $base_cost = array();
            if(!empty($items))
            {
                foreach ($items as $itemId => $item)
                {
                    $qty = intval($item->getQtyOrdered()); //get items quantity
                    if(empty($qty))
                    {
                        $qty = 1;
                    }
                    $b_cost = $item->getBaseCost();//get item cost
                    $base_cost[] = ($b_cost*$qty); //get all items cost
                }
            }
            $total_order_cost = '';
            if(!empty($base_cost))
            {
                $total_order_cost = array_sum($base_cost); //get sum of all items cost
            }
            $profit = '';
            if(!empty($total_order_cost))
            {
                $profit = ($subtotal-$total_order_cost); //get profit , subtraction of order subtotal
            }
 
            $_coreHelper = $this->helper('core');
            $profit = $_coreHelper->currency($profit);
 
            return $profit;
        }
 
    }
}
And you are done, now a Profit column will be seen in Sales > Orders in adminend.


How to get Table Name in Magento

Here is the small snippet of code to get the table name of the particular module.

let us assume my module name is "dckapbanner".

here is the script to get the table name of the "dckapbanner" module.

<?php
 
$resource = Mage::getSingleton('core/resource');
$tableName = $resource->getTableName('dckapbanner/dckapbanner');
 
?>

Thursday, March 29

How to install SSL Certificate in Magento


Here we will see how to install SSL certificate in Magento. Before we go to Magento SSL certificate we have to know all what is SSL and why we need SSL in our website.

What is SSL?

SSL is an acronym for Secure Sockets Layer, an encryption technology that was created by Netscape. SSL creates an encrypted connection between your web server and your visitors’ web browser allowing for private information to be transmitted without the problems of eavesdropping, data tampering, or message forgery. Once you have done the SSL install, you can access a site securely by changing the URL from http:// to https://. When an SSL certificate is installed on a website, you can be sure that the information you enter (credit card or any other information), is secured and only seen by the organization that owns the website.

Why need SSL?

If you are transmitting sensitive information on a web site, such as credit card numbers or personal information, you need to secure it with SSL encryption. It is possible for every piece of data to be seen by others unless it is secured by an SSL certificate.

 Add SSL certificate magento: Please follow the below steps for add SSL certificate in magento Here I show you with example of SSL Certificate add into cpanel.

Step1: Open your CPanel and Goto ssl-tls manager menu. 


Step2: Select Activate SSL on Your Web Site (HTTPS).


Step3: And enter the CRT and KEY for certificate and press install certificate button and install it. 


Step4: After this go to magento admin panel in System->Configuration->web in base url and set https where write http and set Use Secure URLs in Frontend = yes. 



Now you can have ssl certification in your magento site. you can see this in near by your address bar.

Thank You : Just Web Development 

Sunday, March 25

How to print coupon code and gift certificate on magento Invoice PDF

In this article we will see how to print the coupon code and gift certificate while invoice the magento order

here is the complete step by step procedure

Step 1 : Copy /app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php to /app/code/local/Mage/Sales/Model/Order/Pdf/Invoice.php

Step 2 : Find the line $page = $this->insertTotals($page, $invoice); in the getPdf function. This was line 107 for me.

Step 3 : Add the following in the above and save the file
/* added by Wright Creative Labs */
/* print coupon code on invoice */
if($order->getCouponCode()!=""){
    $this->y -=12;
    $page->drawText('Coupon Used: '.$order->getCouponCode(), 450, $this->y, 'UTF-8');    
}
/* print gift certificate code on invoice */
if($order->getGiftcertCode()!=""){
    $this->y -=12;
    $page->drawText('Coupon Used: '.$order->getGiftcertCode(), 450, $this->y, 'UTF-8');    
}

thats it. now you can able to print the coupon and gift certificate in backend sales order.

Monday, March 5

How to Search the product within the top lovel category in Magento

The default magento supports to search the products based the search keyword. if we want to search the products within the specific category we need to change the catalog search template under teample/catalogsearch/form.mini.html

here is the script to search the products within the specific category
<?php
$category = Mage::getModel('catalog/category');
if(is_object(Mage::registry('current_category'))){
    $current_category_path=Mage::registry('current_category')->getPathIds();
}else{
    $current_category_path = array();
}
$category->load(Mage::app()->getStore()->getRootCategoryId());
$children_string = $category->getChildren();
$children = explode(',',$children_string);
$extra_options='';
foreach($children as $c){
    $selected = (in_array($c, $current_category_path))?'SELECTED':'';
    $extra_options.= '<option value="' . $c . '" ' . $selected . '>' . $category->load($c)->getName() . '</option>' . "\n";
}
?>
<form id="search_mini_form" action="<?php echo $this->helper('catalogSearch')->getResultUrl() ?>" method="get">
    <fieldset>
        <legend><?php echo $this->__('Search Site') ?></legend>
        <div class="mini-search">
            <input id="search" type="text" class="input-text" name="<?php echo $this->helper('catalogSearch')->getQueryParamName() ?>" value="<?php echo $this->helper('catalogSearch')->getEscapedQueryText() ?>" />
            <select name="cat" id="cat" class="input-text">
            <option value="">All Categories</option>
            <?= $extra_options ?>
           </select>
            <input type="submit" value="Go" style="border: 1px solid #808080;" alt="<?php echo $this->__('Search') ?>" />
            <div id="search_autocomplete" class="search-autocomplete"></div>
            <script type="text/javascript">
            //<![CDATA[
                var searchForm = new Varien.searchForm('search_mini_form', 'search', '<?php echo $this->__('search site...') ?>');
                searchForm.initAutocomplete('<?php echo $this->helper('catalogSearch')->getSuggestUrl() ?>', 'search_autocomplete');
            //]]>
            </script>
        </div>
    </fieldset>
</form>