Wednesday, September 28, 2011

How to show only first name in magento welcome message?

Comment the welcome message code in "template/page/html/header.phtml" and Use the below code to show first name only.
$customer = Mage::getSingleton('customer/session')->getCustomer()->getData();
if(Mage::getSingleton('customer/session')->isLoggedIn()){
   echo $this->__('Welcome, %s!', $customer['firstname']);
}else{
   echo $this->__('Welcome Guest');
}

Thursday, September 22, 2011

How to find magento version?

There are two ways to see what version of magento you’re using.

Method 1:
Login to the admin for Magento:
http://www.yourdomain.com/admin/
...and look in the footer, you should see the following:
Magento ver. X.X.X
Where X.X.X is the version number.

Method 2:
If you only have access to the source code, Use the below code.
echo Mage::getVersion();
print_r(Mage::getVersionInfo());

How to Enable template path hints for Magento Admin Panel?

When developing a new Magento Admin theme, one of the tools that will make your life easier is the template path hints. One thing this feature is missing, is the ability to show the template path hints on the admin panel. Whether you’re working on a custom admin theme or module or you’re just curious about what’s under the hood, being able the enable the hints in the admin would be a cool feature. Here is the easy way to accomplish this:

Run the following query to enable the hints:
INSERT INTO core_config_data SET scope = 'default', scope_id = 0,
            path = 'dev/debug/template_hints', value = 1;
INSERT INTO core_config_data SET scope = 'default', scope_id = 0,
            path = 'dev/debug/template_hints_blocks', value = 1;
Clear the config cache, Thats it. You have template path hints in the admin. To disable run a sql query to set the value to 0.

Tuesday, September 20, 2011

How to remove an item from magento shopping cart automatically?

$cartHelper = Mage::helper('checkout/cart');
$items = $cartHelper->getCart()->getItems();
foreach ($items as $item) {
    if ($item->getProduct()->getId() == $productId) {
        $itemId = $item->getItemId();
        $cartHelper->getCart()->removeItem($itemId)->save();
        break;
    }
} 
Note:
The ItemId (ID of an item in the cart) is not the same as the ProductId of the product it represents. Try iterating through the items in the cart until you find the one with the ProductId you want to remove.

How to Add a custom State / Province / Region to a Country in magento?

If you need to add a custom State / Province / Region to a Country in Magento, you’ll need to modify the database manually as there currently isn’t a means to do this from within the Magento admin. Fortunately it’s pretty simple – there are 2 tables involved: directory_country_region and directory_country_region_name.

Adding a record to directory_country_region for a specified country_id will make that new entry show up in the State/Province drop box on the address forms. It will also make that a required field, so you need to make sure you add all the possible options.

You then need to add a corresponding record to directory_country_region_name, using the region_id generated when you inserted into directory_country_region. This entry will make the new region show up when a whole address is displayed on the screen or email, e.g. in an order summary.

Example: Add Tamil Nadu to India

So let’s say that like me, you live in India and want to add 2 regions: Tamil Nadu and Kerala. The country id for India is IN, the region code is a unique identifier so I’m going with Tamil Nadu and at the moment I’m only interested in the en_US locale.

First I will insert Tamil Nadu into directory_country_region as follows:
INSERT INTO `directory_country_region`
(`region_id`,`country_id`,`code`,`default_name`)
VALUES (NULL,'IN','TAMIL','Tamil Nadu');
Note the NULL entry for the region_id field which will auto_increment. I need to find out this new region_id for my next insert so I can either browse the table manually, or this query will do the trick:
SELECT * FROM `directory_country_region`
WHERE `country_id`='IN' AND`code`='TAMIL' AND `default_name`='Tamil Nadu';
In my case, the new region_id is 485, so with that I’ll now insert into directory_country_region_name as follows:
INSERT INTO `directory_country_region_name`
(`locale`,`region_id`,`name`)
VALUES ('en_US','485','Tamil Nadu');
Now I just repeat those steps for Kerala and I’m all set.

Got fatal error when i enabling compilation in magento

Open your "root/includes/config.php" file.
Comment the below line using '#' symbol.
define('COMPILER_INCLUDE_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR.'src');
Thats it. Refresh the cache and check now.

How to add CSS and JS files in magento header?

Open your page.xml file and add the below lines
skin_csscss/YOURCSSFILENAME.css
skin_jsjs/YOURJSFILENAME.js
Refresh your cache. Thats it. You are done.