rss
twitter
    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()) ?>

Source: http://www.blog.highub.com/cms/magento-display-product-sku/

Wednesday, January 27, 2010

How to get currency symbol?

Code is useful for get currency symbol
    
     Mage::app()->getLocale()->currency(Mage::app()->getStore()->
     getCurrentCurrencyCode())->getSymbol()

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

     Mage::app()->getLocale()->currency('EUR')->getSymbol()


Source  : http://www.activecodewar.com/

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);
        section.addClassName('allow');
        this.accordion.openSection(section);
    };
</script>
 
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 : http://snippi.net/magento-report-each-step-magentos-one-page-checkout-google-analytics

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()
->load();
foreach($collection as $product) {
var_dump($product->getData());
}

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( '*' )
->load();
foreach($collection as $product) {
var_dump($product->getData());
}

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

$collection= Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('entity_id',
array('in'=> array(16,17,19,20) )
)
->load();
foreach($collection as $_prod) {
var_dump($_prod->getData());
}

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

$collection= Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('entity_id',
array('in'=> array(16,17,19,20) )
)
->load();
foreach($collection as $_prod) {
var_dump($_prod->getData());
}

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()
->addAttributeToSelect('*')
->setPageSize(5)
->setCurPage(1)
->load();
foreach($collection as $_prod) {
echo $_prod->getName();
}

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

$collection=Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*');
$collection->getSelect()->limit(5);
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 : http://www.bysoft-technologies.com/blog/magento/a-brief-introduction-to-magento-collection/478

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:

Code:

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

Source : http://www.blog.highub.com/cms/magento-check-if-user-logged-in/

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:

      <?php
      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 127.0.0.1 (note the backslashes before dots) should be replaced with your IP-address (check www.whatsmyip.com 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 : http://www.silverthemes.com/blog/2010/01/restrict-access-to-magento-during-upgrades-etc/

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 : http://www.magento-tutorial.com/

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 : http://www.codefight.org/

Tuesday, January 12, 2010

Edit the default Magento eMail Templates

How to edit the default Magento Email templates. They are stored in:
\app\locale\en_US\template\email\

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 mailto:magento@varien.com with mailto:email@yourstore.com

replace dummyemail@magentocommerce.com with email@yourstore.com

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:
/skin/frontend/default/modern/images/logo_email.gif

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

Source : http://blog.rogueeasyweb.com/?p=39

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 : http://www.magento-vietnam.com/magento-tips-tricks/javascript-magento-not-working/

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 : http://blog.chapagain.com.np/how-to-install-sample-data-for-magento/

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.

<?php
//-------------------------------------------
// ADWORDS CONVERSION TRACKING
//-------------------------------------------
$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>
<script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<img height="1" width="1" border="0" src="http://www.googleadservices.com/pagead/conversion/---YOUR_GOOGLE_CONVERSION_ID---/?label=purchase&guid=ON&script=0"/>
</noscript>

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 : http://www.free-ebusinesshelp.com/magento/magento-adwords-conversion-tracking.html

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 : http://www.learnmagento.org/magento-tutorials/newsletter-subscribe-page-in-magento/

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"?>
<config>
    <modules>
        <Mage_Page>
            <active>true</active>
            <codePool>local</codePool>
        </Mage_Page>
    </modules>
</config>
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”
<layouts>
 <home module="page" translate="label">
        <label>Home</label>
        <template>page/home.phtml</template>
        <layout_handle>page_home</layout_handle>
    </home>
    <empty module="page" translate="label">
        <label>Empty</label>
        <template>page/one-column.phtml</template>
        <layout_handle>page_empty</layout_handle>
    </empty>
    <one_column module="page" translate="label">
        <label>1 column</label>
        <template>page/1column.phtml</template>
        <layout_handle>page_one_column</layout_handle>
    </one_column>
    <two_columns_left module="page" translate="label">
        <label>2 columns with left bar</label>
        <template>page/2columns-left.phtml</template>
        <layout_handle>page_two_columns_left</layout_handle>
    </two_columns_left>
    <two_columns_right module="page" translate="label">
        <label>2 columns with right bar</label>
        <template>page/2columns-right.phtml</template>
        <layout_handle>page_two_columns_right</layout_handle>
    </two_columns_right>
    <three_columns module="page" translate="label">
        <label>3 columns</label>
        <template>page/3columns.phtml</template>
        <layout_handle>page_three_columns</layout_handle>
    </three_columns>
</layouts>

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 : http://thinclay.artician.com/blog/2009/12/magento-add-new-cms-page-layout/

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:
app/design/frontend/*/*/template/callouts/right_col.phtml
app/design/frontend/*/*/template/callouts/left_col.phtml

You will also find that the block is being added onto your Magento install via catalog.xml
app/design/frontend/*/*/layout/catalog.xml

For the right column:

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

to

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

You can do the same for the left callouts


http://www.exploremagento.com/magento/moving-removing-callouts-on-the-left-right-columns.php