Get customer detail using email address in magento

Suppose we have the customer email id and we want to fetch all details of that customer in Magento, its very easy and you can use below code it will give you all information with the email address which you have added in $email.

$customerExist = Mage::getModel('customer/customer')
->addAttributeToFilter('email', $email )

Model-View-Controller MVC

Model-View-Controller MVC

=> Model
Model is the classes providing data, service related to data and business logic. This class works directly with data and provides data for other elements. In a module, these classes are contained in Model folder.

=> View
View is the classes which define data presented method (not update data). These classes are contained in the folder Block of module.

=> Controller
Controller is the classes which control application stream. They receive input which is requirement of users through HTTP request, transfer those requests to the classes which process the requests directly. From the link, Router will get to Controller which controls that link. In Magento module, these classes are contained in controller folder.

Call phtml file in Magento

1) Magento: call phtml file in CMS page.

When you want to display dynamic content on home page or any other CMS page. You just need to create block of specific module which create an object of that module and call predefined methods of that module to fetch date and call that modules phtml file.

Below is code by using you can call phtml file in CMS page.

{{block type="core/template" template="templateFolder/your_template.phtml"}}

2) Magento: call phtml file in static block.

You can use same syntax as CMS page

{{block type="core/template" template="templateFolder/your_template.phtml"}}

3) Magento: call one phtml file in another phtml file.

To call any phtml fine in another phtml file you just need to add below code in phtml file.

echo $this->getLayout()->createBlock('core/template')->setTemplate('templateFolder/your_template.phtml')->toHtml();

4) Magento: call phtml file using XML file.

To call any phtml file using XML you need to add below code in reference block where you want to show that block.
i.e if you want to add phtml file in footer at that time you need to add below code in <reference name=”footer”> in page.xml

<reference name="footer">
<block type="core/template" name="unique_name" template="templateFolder/your_template.phtml"/>

Call static block in Magento

Static block is use to allow store Admin to update content or any block without changing code. Admin can update content from admin-panel easily. We can call static block in different location in Magento. I.e. in CMS page,
any of phtml file, any block etc.

Below are syntax to call static block in different location.

1) Magento: call a static block in a phtml file.

To call a static block in a phtml file you just need to replace static block id in below code. Put this code where you want to call.

echo $this->getLayout()->createBlock('cms/block')->setBlockId('static_block_id')->toHtml();

2) Magento: call a static block in CMS page.

use below code to call static block in CMS page.

{{block type="cms/block" block_id="static_block_id"}}

3) Magento: call static block in xml.

syntex to call static block using xml file

<block type="cms/block" name="home-page-block">
<action method="setBlockId"><block_id>home-page-block</block_id></action>

Steps to activate logs in magento using admin panel

using below steps you can enable logs in magento

1) Login in magento back-end
2) Go to System -> Configuration
3) from left section click on Advanced -> Developer
4) you can able to see Log Settings in main section click on it
5) Enabled set this option ‘YES’ and click on ‘save’ button on right top corner.

Now you can able to see log files in var/log folder

Improve performance of Magento store using htaccess

Magento store have 300+ default database tables. Also Magento using EAV database structure that make magento store very slow. To improve magento store performance using htaccess. we have to do some changes in .htaccess file.

## enable apache served files compression

# Insert filter on all content
SetOutputFilter DEFLATE
# Insert filter on selected content types only
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript

# 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

Script to get all product magento

Below is the script which display all magento product

create new file in root of the magento source and add below code in that file

$_productCollection = Mage::getModel('catalog/product')
->addAttributeToSort('created_at', 'DESC')
foreach ($_productCollection as $_product){
echo $_product->getId().'</br>';
echo $_product->getName().'</br>';
echo $_product->getProductUrl().'</br>';
echo $_product->getPrice().'</br>';

Add JQuery in Magento

To add Jquery in magento we need to add below code in layout file.

/app/design/frontend/package/your theme/layout/page.xml
<reference name="head">
<block type="page/html_head" name="head" as="head">
<action method="addItem">
<name>Jquery path with name</name>

Script to get all category in magento.

External script to Display All category which are created in magento.
Below is the code to display all category.

create new file in root of the magento source and add below code in that file

require_once 'app/Mage.php';
$app = Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$categoriesArray = Mage::getModel('catalog/category')
->addAttributeToSort('path', 'asc')
$categories = array();
foreach ($categoriesArray as $categoryId => $category) {
if (isset($category['name']) && isset($category['level'])) {
$categories[] = array(
'level' => $category['level'],
'label' => $category['name']
echo "<pre>";

Above code will display all categories as below screenshot: