Tips for Magento site speed up

Tips for Magento site speed up Summary:

  • Enable all Magento caching layers.
  • Configure your web server to enable Connection Keep-Alive, enable mod_expire, gzip compression.
  • Enable MySQL Query caching.
  • Install APC or XCache to cache PHP opcode.
  • Install Memcache and configure Magento to store session and cache to memory.
  • Install third-party Full Page Cache Magento extension.
  • Install Varnish cache server for full page caching on system layer.

Getting The Amount Of Items in the Cart in Magento

To get the amount of line items (i.e. 10 of 1 product is 1):

Mage::helper('checkout/cart')->getItemsCount();

To get the total number of items (i.e. 10 of 1 product is 10):

Mage::helper('checkout/cart')->getSummaryCount();

How to show maintenance mode page in magento (website under construction)

If you want your Magento website to show in maintenance mode, you will have to do two things.
1. Create a file name maintenance.flag in your magento root directory. Contents under this file doesn’t matter, you can keep it empty.
2. Change the maintenance file (located in magento root -> errors -> default directory) to show proper message when user visits your website.

How to join EAV collection with Flat table in Magento

Joining tables in Magento when it comes to EAV with Flat table is quite complicated. Consider you want to join sales_flat_order table with customer EAV tables to get Customer’s firstname and lastname, it becomes difficult as customer’s name comes from customer_entity_varchar table.
Here is code for customer EAV to get customer’s full name in the collection along with all the order details.

$value = Mage::getModel('sales/order')->getCollection();
 
$fn = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'firstname');
$ln = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'lastname');
 
$value->getSelect()
    ->join(array('ce1' => 'customer_entity_varchar'), 'ce1.entity_id=main_table.customer_id', array('firstname' => 'value'))
    ->where('ce1.attribute_id='.$fn->getAttributeId()) 
    ->join(array('ce2' => 'customer_entity_varchar'), 'ce2.entity_id=main_table.customer_id', array('lastname' => 'value'))
    ->where('ce2.attribute_id='.$ln->getAttributeId()) 
    ->columns(new Zend_Db_Expr("CONCAT(`ce1`.`value`, ' ',`ce2`.`value`) AS fullname"));
 
print_r($$value->getData());

Click Here to know more

Add New Custom Page Layout in Magento 1.7

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 Love_Home.xml in app/etc/modules

Insert the following code into the file:


<?xml version="1.0"?>
<config>
<modules>
<Love_Home>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Page/>
</depends>
</Love_Home>
</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/Love/Home/etc/config.xml

Insert the following code into the file:


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


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

app/design/frontend/default/YOUR_THEME/page/home.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.