Monthly Archives: September 2012

Magento Create Own Log files

Magento comes with a built-in logging facility which can be enabled and configured in the back-end under System > Configuration > Developer. Alternatively you can enable the Developer Mode for the site to enable the log (on how to do this have a look at the index.php file). The exception log is always on.

Magento Comes with a built-in Logging Facility Which can be enabled and configured

1. Enable developer mode in the .htaccess file by adding:

2. Enable log settings going to:
System » Configuration » Developer, Log settings tab » Enabled » Yes.

Mage::log('My log entry');

Mage::log('My log message: '.$myVariable);




By default all log entries are appended to the var/log/system.log file and the exceptions are logged to var/log/exception.log.

For Eaxample

Looking at the method definition in app/code/Mage.php you will find
public static function log($message, $level = null, $file = ”) {}

so if you want to create own log that can be done by
Mage::log(‘My log entry’, null, ‘mylogfile.log’);

and will all our log entries are in their own file at var/log/mylogfile.log. Exceptions can only be logged to one file

Magento Add new input type in custom options

By Default Magento Product Custom options has following field which have radio,checkbox,Multiple select,Select….so if we need to add new input type in that custom options so here is the codeNote : Make sure that Don’t disturb the Core Files always use Magento Standard
1) Open the file and copy in local folder


<multiplenew translate="label" module="adminhtml">

<label>Multiple Select New</label>


2) Open the file and copy in local folder


array('value' => 'multiselectnew', 'label' => Mage::helper('eav')->__('MultipleNew Select')),

3) Open the file and copy in local folder


In this file you will found three case of multiple just above that

case ‘multiple’: //already there line 152

case ‘multiplenew’: //add above

case ‘multiple’: //already there line 211

case ‘multiplenew’://add above

case ‘multiple’: //already there line 233

case ‘multiplenew’://add above

case ‘multiple’: //already there line 265

case ‘multiplenew’://add above

Note :Here Multiplenew is the new field

Clear the cache and run new input type will come.Hope this will help you!

Use Magento Outside of Install Directory

One of the coolest parts of using Magento is that it can be accessed from different parts of the server even if you’re not within the Magento root Directory then also you can access it’s functionlity

The main important or you can say life of magento is Mage.php, we need to access Mage.php because It holds the Mage class and defines some of the root functionality of Magento like retrieving the model, setting up the BaseUrl path and calling the rest of the

Create one file called test.php and and add the below code

require_once '/your-path-upto/Mage.php';



That’s it Magento will get access from outside and it is ready for work

For Accsssing the Customer login Session we can use

Mage::getSingleton('core/session', array('name' => 'frontend'));

$session = Mage::getSingleton('customer/session');        


In this way we can called all product collection,sales model,checkout etc…..

Hope You this will help you!

Magento Add attribute Filter

Magento has filterable condition which help to sort out the result.Let Look How it works

addAttributeToFilter is a function that can be called on a product collection in Magento. it adds a condition to the WHERE part of the MySQL query used to extract a product collection from the database

For Example:

$_products = Mage::getModel('catalog/product')->getCollection()

   ->addAttributeToSelect(array('name', 'product_url', 'small_image'))

   ->addAttributeToFilter('sku', array('like' => 'UX%'))


The above code would get a product collection, with each product having it’s name, url, price and small image loaded in it’s data array. The product collection would be filtered and contain only products that have an SKU starting with UX.

so here Filter Condition have ‘sku’ with ‘like’ opertor which will help to filter result based on SKU

There are More Filterable Condition which we can used while filtering

Equals: eq
$_products->addAttributeToFilter(‘status’, array(‘eq’ => 1));

Not Equals – neq
$_products->addAttributeToFilter(‘sku’, array(‘neq’ => ‘test-product’));

Like – like 
$_products->addAttributeToFilter(‘sku’, array(‘like’ => ‘UX%’));

Note :One thing to note about like is that you can include SQL wildcard characters such as the percent sign.

Not Like – nlike
$_products->addAttributeToFilter(‘sku’, array(‘nlike’ => ‘err-prod%’));

In – in
$_products->addAttributeToFilter(‘id’, array(‘in’ => array(1,4,74,98)));

Note:When using in, the value parameter accepts an array of values.

Not In – nin 
$_products->addAttributeToFilter(‘id’, array(‘nin’ => array(1,4,74,98)));

NULL – null 
$_products->addAttributeToFilter(‘description’, ‘null’);

Not NULL – notnull
$_products->addAttributeToFilter(‘description’, ‘notnull’);

Greater Than – gt
$_products->addAttributeToFilter(‘id’, array(‘gt’ => 5));

Less Than – lt 
$_products->addAttributeToFilter(‘id’, array(‘lt’ => 5));

Greater Than or Equals To- gteq
$_products->addAttributeToFilter(‘id’, array(‘gteq’ => 5));

Less Than or Equals To – lteq
$_products->addAttributeToFilter(‘id’, array(‘lteq’ => 5));

Hope this Will Help You!

Magento 1.3 and Magento 1.4 Fix "call to member function toHtml()"

One of the errors you will usually encounter when you use a theme made for Magento 1.3 on Magento 1.4.1 0 version is that

“call to a member function toHtml()”. There is a very easy fix for this error.

The Error comes like line number may differ

Fatal error: Call to a member function toHtml() on a non-object in                                                                      \app\code\core\Mage\Core\Model\Layout.php on line 529

just open the


Replace with

that’s it the error will resolved just refresh the front end..Hope this will help you

Magento Local.xml for updating and Overriding XMl Structure

As Magento had important role of XML.while chnaging themes or Removing any block or layout chnages we are going in the each xml file of our theme and changing but there is one more solution that each time we don’t need to update the each  xmlThe idea behind is the local.xml, placed inside your theme layout folder to override or update all xml references for that theme.

Every change to the local.xml file is evident so there is no need to search for changes inside xml files

How set up works

1. Create the local.xml inside your theme layout folder (app/frontend/default/yourtheme/layout)

2. Add basic xml structure

< ?xml version="1.0"?>
<layout version="0.1.0"></layout>

Let us take few example

1. Removing/Adding javascript from the section:

<!-- remove flex js for IE7-->
<reference name="head">
<action method="removeItem"><type>js</type><name>lib/flex.js</name><params /><if>lt IE 7</if></action>

<!-- Instead, add slider.js from your theme /js folder -->
<action method="addItem"><type>skin_js</type><name>js/slider.js</name><params /><if>lt IE 7</if></action>

2. Add a layout change for the category page only. Setting a template and adding some javascript

<catalog_product_view translate="label">

<reference name="root">

<action method="setTemplate">




<reference name="head">

<action method="addItem"><type>skin_js</type><name>js/tabs.js</name></action>

<action method="addItem"><type>skin_js</type><name>js/boxes/boxes.js</name></action>



3. Remove specified blocks from the layout (products compare, products viewed and related products) using remove tag


<reference name="right">

<remove name="" />

<remove name="left.reports.product.viewed" />

<remove name="catalog.product.related" />



4. Remove specified blocks from the layout (products compare, products viewed and related products) using method unsetChild tag


<reference name="left">

<!-- Removed the Newsletter from the left sidebar -->

<action method="unsetChild"><name>left.newsletter</name></action>

<action method="unsetChild"><name>tags_popular</name></action>



this way you can used the local.xml.Hope this wil help you