Find out what I'm doing, Follow Me :)

Friday, January 29, 2010

Magento Display Product SKU

If you happen to use Magento to develop your e-commerce site, and want to display SKU number on your product page, here is how you can use the magic method getSku to do it. On your app/design/frontend/default/default/template/catalog/product/view.phtml page, add in the line below:

<?php echo 'RN #'.nl2br($_product->getSku()) ?>


Wednesday, January 27, 2010

How to get currency symbol?

Code is useful for get currency symbol

or if you want to pass a certain currency code simply specify it:


Source  :

Tuesday, January 26, 2010

Report each step of Magento's One Page Checkout to Google Analytics

This code allows you to track each step of Magento's One Page Checkout in Google Analytics.

The code should be installed at the bottom of the /app/design/frontend/default/YOUR_TEMPLATE_NAME/template/checkout/onepage.phtml template file.

 <script type="text/javascript">
    // Report each step of the checkout process to Google Analytics
    Checkout.prototype.gotoSection = function(section) {
        try {
            pageTracker._trackPageview('<?php echo $this->getUrl('checkout/onepage') ?>' + section + '/');
        } catch(err) { }
        section = $('opc-'+section);
Once installed, you can Create a Conversion Goal.
1. Goal Name: Successful Purchase
2. Active Goal: On
3. Goal Position: Set 1, Goal 1 (I didn't have other Goals, so this was the position I used.)
4. Goal Type: URL Destination
5. Match Type: Head Match
6. Goal URL: /checkout/onepage/success/
7. Create your Goal Funnels as follows;
Step 1: /checkout/onepage/
Step 2: /checkout/onepage/billing/
Step 3: /checkout/onepage/shipping/
Step 4: /checkout/onepage/shipping_method/
Step 5: /checkout/onepage/payment/
Step 6: /checkout/onepage/review/

Source :

Monday, January 25, 2010

A brief introduction to Magento Collection

A collection is a Model type containing other Models, it is basically used in Magento to handle and manipulate product lists.

Let’s have a look at the code!

The first thing to do is to retrieve the products’ model from module Mage/Catalog, and then get the collection of products:

/* Load a collection with all products */
$collection = Mage::getModel('catalog/product')->getCollection()
foreach($collection as $product) {

Note that by default, Magento doesn’t load all the attributes.

/* Load a collection with all products and all products' attributes */
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect( '*' )
foreach($collection as $product) {

The collection is a powerfull tool that allows you to filter or sort the list according to EAV attributes using the method

$collection= Mage::getModel('catalog/product')->getCollection()
array('in'=> array(16,17,19,20) )
foreach($collection as $_prod) {

The following example show how to filter on a particular attribute.

$collection= Mage::getModel('catalog/product')->getCollection()
array('in'=> array(16,17,19,20) )
foreach($collection as $_prod) {

The complete list of short SQL conditions allowed can be found in lib/Varien/Data/Collection/Db.php under method _getConditionSql

You can also specify an amount of product you want to display, using methods setPageSize($size) and setCurPage($page):

$collection= Mage::getModel('catalog/product')->getCollection()
foreach($collection as $_prod) {
echo $_prod->getName();

On other way to do this is by using limit() method:

foreach($collection as $item){
echo $item->getName();

Note: if you use limit() method to limit collection, you can’t use load() method here, otherwise you will get all products.

Source :

Saturday, January 23, 2010

Magento – check if user logged in

Many times, you may want to check if a user is logged in while using Magento, to do so, you could use one of the many helper function to do so. The top class for it is Class Mage_Customer_Helper_Data, the method we are going to use is isLoggedIn(), let’s write a simple script to check if a user is logged in:


if ($this->helper('customer')->isLoggedIn() ) {
    echo "Welcome!";
} else {
    echo "Please log in.";

Source :

Friday, January 22, 2010

Restrict access to Magento during upgrades etc

We get many requests about how to restrict access to Magento during upgrades or other issues that requires that Magento is not available for customers and search spiders, but is still accessible for you to debug.

Here is an example of restricting your Magento instance to your IP address exclusively. Other visitors, including search spiders, will get the HTTP503 Service Unavailable error.

First, create a file 503.php in your Magento installation root:

      header(‘HTTP/1.1 503 Service Unavailable’);
      header(‘Content-Type: text/plain; charset=UTF-8');
      echo "503 Service Unavailable";

In .htaccess or in Apache server configuration, add the following rewrite rule:

Where (note the backslashes before dots) should be replaced with your IP-address (check to find your IP.

Once you save this .htaccess file or reload Apache configuration, your site will be down until you restore the initial state.

Source :

Wednesday, January 20, 2010

Add a javascript file to your magento page templates

Customising your magento store can be a good way to set your store apart from the competition so adding features that require javascript files is a common task when building a project.  Learn how to include a javscript file into your magento page templates with this quick how to.The default layout template load is made primarily through the page.xml file located at the following url for custom themed installs /app/design/frontend/your-instance-name/your-theme-name/layout/page.xml , or for the default theme at /app/design/frontend/default/default/layout/page.xml.

Find the following block encapsulator <block type="page/html_head" name="head" as="head"> and simply add the following command inside the block

<action method="addJs"><script>yourscriptname.js</script></action>

Then upload you updated page.xml file. 

With that done, you need to now upload your javascript file to /skin/frontend/your-instance-name/your-theme-name/js/yourscriptname.js, or for the default theme /skin/frontend/default/default/js/yourscriptname.js

Source :

Tuesday, January 19, 2010

How to get item/product counts in cart?

$_cart = Mage::getModel('checkout/cart');

echo"getItemsQty-" . ($_cart->getItemsQty());
echo"getItemsCount-" . ($_cart->getItemsCount());
echo"getSummaryQty-" . ($_cart->getSummaryQty());

Source :

Tuesday, January 12, 2010

Edit the default Magento eMail Templates

How to edit the default Magento Email templates. They are stored in:

Be aware that not all files in the folders need editing, and some templates have info in different spots, so be attentive.

Edit the following info:

replace alt=”Magento” with alt=”your store name”

replace Magento Demo Store with your store name

replace with

replace with

replace (800) DEMO-STORE with (0800) YOUR STORE NUMBER

replace Monday - Friday, 8am - 5pm PST with your own store opening times and timezone

To replace the logo image, make a new image, (The default magento image is 169×49 for reference) name it logo_email.gif and put it here:

You may also change aspects of the templates in the magento administration under
system –> transactional emails.

Source :

Monday, January 11, 2010

javascript in Magento Not Working (js 404 error)

While i was installing a Magento oscommerce platform I encountered a problem, a new problem i might add, because i never saw it before. I’ve worked before with Magento but never had any issues. This time, after getting it up and running i noticed that my admin menu wasn’t working, the options weren’t dropping down as usual.

You obviously can’t work without a menu so i started googling the issue. The first page i looked into gave some indications but nothing clear, and those guys we’re having the problem on ver 1.0 of Magento which is really old.

After trying and testing various methods i finally got it to work, and here is how i did it:

    * step1: replace app/code/core/Mage/Page/Block/Html/Head.php with this head head.php
    * step2: chmod 755 the js/ folder, and folders within.
    * step3: chmod 644 the javascript files inside js/lib/
    * step4: chmod 644 js/index.php

Source :

Friday, January 8, 2010

How to Install Sample Data for Magento?

1) Download Sample Data zip file from Magento Website

2) Extract the zip file

3) Drop all the tables from your magento database. It would be easy to drop the magento database and then recreate it instead of dropping individual tables.

4) Import sample data sql file into your magento database.

# Remember that, you have to drop all tables from your magento database before importing the sample sql file. You will get error afterward if you import the sample data without dropping tables from your magento database. Therefore, step 3 is important.

5) Go to your magento installation folder and delete local.xml file present inside app/etc folder.

6) Reinstall magento.

# After you installation is complete, you may get error something like this:
Integrity constraint violation: 1062 Duplicate entry ‘1' for key 1

Clear your browser cache or open your website in another browser and you are done.

Source :

Wednesday, January 6, 2010

Magento - AdWords Conversion Tracking

When you use Google AdWords to receive more traffic, don’t forget to track the traffic. AdWords Conversion Tracking is a free tool to help you understand how many users actually buy products or services from you.

Installing AdWords conversion tracking codes is pretty straightforward.

Open the file /app/design/frontend/your_interface/your_theme/template/checkout/success.phtml.

Find the following code in the file.

<?php echo $this->__(’Your order # is: %s’, $this->getViewOrderUrl(), $this->getOrderId()) ?>.
<?php else :?>
<?php echo $this->__(’Your order # is: %s’, $this->getOrderId()) ?>.
<?php endif;?>

Add the following code under the above code. If your success.phtml is customized, add it at the end of the file. In most cases, it should work.

$order_details = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$adwords_saleamt = $order_details->subtotal;
<!-- Google Code for Purchase/Sale Conversion Page -->
<script language="JavaScript" type="text/javascript">
var google_conversion_id = ---YOUR_GOOGLE_CONVERSION_ID---;
var google_conversion_language = "en";
var google_conversion_format = "1";
var google_conversion_color = "ffffff";
var google_conversion_label = "purchase";
var google_conversion_value = "<?php echo $adwords_saleamt; ?>";
<script language="JavaScript" src="">
<img height="1" width="1" border="0" src=""/>

To look at the conversion data from Google AdWords, generate reports as follows:

Reports -> Create Report -> ... ->
Add or Remove Columns from Advanced Settings (Optional) -> Choose conversion related columns.

This code is to track conversion rate for regular sales.

Source :

Monday, January 4, 2010

Newsletter Subscribe Page in Magento

Magento has a nice inbuilt feature of Newsletter Subscription , but sometimes you may need to call it to a CMS page.

So, in order to do that, you can just use this code,

{{block type="newsletter/subscribe" template="newsletter/subscribe.phtml"}}

Just place it on your CMS page and clear your cache. Thats done.

Source :

Friday, January 1, 2010

Magento: Add New CMS Page Layout

Want to take your Magento Themes to the next level? Have multiple layouts? If you’re looking to add a new page layout in Magento, create a custom layout or create a new theme layout then this solution is probably for you.
Add a new CMS Page Layout

First we have to create a module. Create file: app/etc/modules/Mage_Page.xml
<?xml version="1.0"?>
Then copy this whole folder: app/code/core/Mage/Page to app/code/local/Mage
What we’ve done is taken a core module and copied it into our local module. This lets us override any core functionality without have to worry about it breaking in future update (or undoing if you mess up).
Now we need to edit: app/code/core/Mage/Page/etc/config.xml and look around line 46 and you can define your own layout, I’m going to call mine “home”
 <home module="page" translate="label">
    <empty module="page" translate="label">
    <one_column module="page" translate="label">
        <label>1 column</label>
    <two_columns_left module="page" translate="label">
        <label>2 columns with left bar</label>
    <two_columns_right module="page" translate="label">
        <label>2 columns with right bar</label>
    <three_columns module="page" translate="label">
        <label>3 columns</label>

Now all you have to do is make a template for this page. Navigate to your theme directory: app/design/frontend/YOUR_THEME/YOUR_THEME/template/page/ and create a new template called home.phtml. I suggest using another existing template as a starting point, such as 3columns.phtml so that you know what variables to work around. This will enable a custom layout option for CMS pages once you’re finished. I’ve tested this with 1.3 series but nothing previous or after that.

Source :

Moving / Removing Callouts on the left / right columns

I recently answered a question on the magento forums about how to remove the callout images in the right / left columns.

This is a pretty easy task, but finding them required a small bit of digging (as usual).

My first recommendation when trying to find any thing in the front end is to turn on Template Path hints in the admin section

   1. Admin > System > Configuration
   2. Switch your "Current Configuration Scope" to your store (’Main Website’ on a stock build)
   3. Click on the Developer Tab (bottom left) and find the Debug area
   4. Template Path Hints: Yes (also might want to add Block Names to hints)

You will find that the template files (phtml files) which include the html for the callouts are located at:

You will also find that the block is being added onto your Magento install via catalog.xml

For the right column:

<reference name="right">
<block type="core/template" before="cart_sidebar" name=""
<block type="core/template" name="right.permanent.callout" template="callouts/right_col.phtml"/>


<reference name="right">
<block type="core/template" before="cart_sidebar" name=""
<!--<block type="core/template" name="right.permanent.callout" template="callouts/right_col.phtml"/>--> <!-- or delete this line altogether -->

You can do the same for the left callouts