Get Price Including Tax In Magento Programmatically

Thursday, 26. April 2012

If you ever wanted to display Prices including VAT/Tax on list.phtml or view.html files in Magento programmatically this snippet may help ya!

echo $this->helper('tax')->getPrice($_product, $_product->getPrice(), true);

Google base feeds shipping attribute Specification

Tuesday, 24. April 2012

Google now requires we submit delivery for UK feeds for each product. If your feeds have recently failed this may well be one reason for this.

To comply there are two ways you can achieve this submission with your future feeds.

1) Specify Delivery in your Google Merchant account.
You can also specify a general delivery cost/infromation in your Google Merchant Account. You can learn more here

2) Add Delivery Information with Google Base feeds
You can add another column in your feeds file called “shipping” and specify shipping costs for each product.

This attribute provides the specific shipping estimate for the product. Providing this attribute for an item overrides the global shipping settings you defined in your Google Merchant Center settings.

This attribute has four sub-attributes:

country (required): The country to which an item will be delivered (as an ISO 3166 country code). The default value for this sub-attribute is your feed’s target country.

region (optional): The geographical region to which a delivery rate applies, e.g. in the US, the two-letter state abbreviation, ZIP code or ZIP code range, using * wildcard.

service (optional): The name of the shipping method.

price (required): Fixed delivery price.

You can include this attribute up to 100 times per item to specify shipping cost for individual regions. If you decide to submit it explicitly for each part of the country, make sure to cover each region or to specify if the item has free shipping.

Learn More About Google Product Feeds (GB/EU) Here!

Hope this helps you!

Change Copyright Year At Footer Of magento

Monday, 16. April 2012

Was asked once by client how to make the copyright year at the footer of Magento site so that it changes automatically every year without doing it manually every year and my answer was this!

1) Log in to your Magento admin panel

2) Navigate to system > configuration > General > Design.

3) Click to expand the Footer section

4) Inside the Copyright text field replace the @copy; YYYY with

&copy; <script type="text/javascript">
var d = new Date();

Save and Clear your cache!

Add custom attributes to Magento product grid or listing page

Saturday, 14. April 2012

Thought this will help someone. If you want to use a custom attribute in category product listing pages follow these steps below:

1) Ensure addAttribute Method exists
Navigate to app/code/core/Mage/Catalog/Block/Product/List.php. Search for a method called addAttribute

This should already been added with new versions of Magento, but if your version doesn’t have it. Copy this file to


Then before the end of class add this script:

   * Use this method in layouts for extra attributes
   * @param string $code internal name of attribute
  public function addAttribute($code)
    return $this;

2) Update your catalog.xml file
Once we have the method in place. Now navigate to your theme’s catalog.xml file and open it.
– Look for handlers catalog_category_default and catalog_category_layered
– then add your attribute codes as show below:

    <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">			
	<action method="addAttribute"><name>attribute_code</name></action>
	<action method="addAttribute"><name>attribute_code2</name></action>

3) Use your attribute in list.phtml page
Now you can use the attribute in your theme’s list.phtml page just as normal.

    echo $_product->getAttributeCode(); # OR
    echo $_product->getData('attribute_code2'); # OR
    echo $_product->getAttributeText('attribute_code2');


Zend_Db_Statement_Exception Lock wait timeout exceeded try restarting transaction

Friday, 13. April 2012

If you have ever come across this error Next exception ‘Zend_Db_Statement_Exception’ with message ‘SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction’ while running long queries these can possibly be one of your solutions

1) Best option is to try and reduce/break the size of your query into small queries.

2) If reducing the size of your queries is not an option, you may try this. In you my.cnf file (somewhere /etc/mysql/my.cnf) look for and change/add the following entry

innodb_lock_wait_timeout = 50 # Set this to a big number to cater your needs!

REMEMBER: You will need to Restart mysql for changes to take effect. Then re-run your query.

Remember to change the value back to small number while on production server. Its there as a small value for a reason!!

Zend_Cache_Exception can’t get apc memory size

Thursday, 12. April 2012

trying to run Magento indexes on command line is an excellent way to get things done rather quickly. However there are times it can be rather annoying and more so when performance enhancement measueruses such as APC cache is in place.

A common error with APC cache exception ‘Zend_Cache_Exception’ with message ‘can’t get apc memory size’ in lib/Zend/Cache.php:209 can be very annoying and if like me you have been scratching your head over this, the post may be your solution.

After soul searching I came to find out this is merely a configurations issue and the most common settings you need are these below.
apc.enable_cli=1    # VERY IMPORTANT

You will need to add these entries to your apc.ini file that can be found (at least on my server)


REMEMBER you will need to restart apache for these changes to take effect.


How To Load Product By SKU and Other Attributes in Magento

Thursday, 12. April 2012

A quick way to load product by sku in magento is by using the load and/or loadByAttribute methods of the product’s model class. Here are some examples

Load Product By loadByAttribute() method
The loadByAttribute methods format is like this

$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);

Load by the load() method

$product = Mage::getModel('catalog/product')->load($sku,'sku');


Magento Index Management On Command Line

Wednesday, 11. April 2012

Get Magento Indexer Codes
– Open your command line tool
– Navigate to your magento’s folder and type this command

php -f shell/indexer.php info

Magento Indexers Codes
Here is a list of all default indexers codes as of Magento 1.6.x

catalog_product_attribute     Product Attributes
catalog_product_price         Product Prices
catalog_url                   Catalog URL Rewrites
catalog_product_flat          Product Flat Data
catalog_category_flat         Category Flat Data
catalog_category_product      Category Products
catalogsearch_fulltext        Catalog Search Index
cataloginventory_stock        Stock Status
tag_summary                   Tag Aggregation Data

Check status of all indexes
– Open your command line tool
– Navigate to your magento’s folder and type this command

php -f shell/indexer.php --status # shows status for all indexers
php -f shell/indexer.php --status <indexer> # Show status for specific Indexer

How to run the index management

php -f shell/indexer.php --reindex <indexer>  # Index a specific indexer

— Index all indexers

php -f shell/indexer.php --reindex all

— Index all indexers but Catalog Search Index

 php indexer.php --reindex "catalog_product_attribute,catalog_product_price,catalog_url,catalog_product_flat,catalog_category_flat,catalog_category_product,cataloginventory_stock,tag_summary"

The <indexer> can be: – Comma separated indexer codes or value “all” for all indexers

Setting Up Magento Cron Jobs Via SSH Command Line

Tuesday, 10. April 2012

Setting up cron jobs via command line tool is easy if you know how. First you will need to open the cron tab before you can enter and schedule your tasks.

This simple walk through will shade some lights on how to do just that and what are the required setting to complete a successful job setup.

1) Opening the Cron Tab

To open the cron tab as the user you are logged in as type:

crontab -e

To open the cron tab as a specific user, type:

crontab -u USERNAME -e

Time Format Steps:
minute hour day month day-of-week

minute 0-59
hour 0-23
day 1-31
month 1-12
day-of-week 0-7 (where both 0 and 7 mean Sun, 1 = Mon, 2 = Tue, etc)

This is how the cron should look

min hour day month dayofweek command_to_run

Examples: What stuff really means

0 1 * * *  ==> Every day at 1Am
* * * 12 * ==> December
14,29,44,59 * * * * ==> at after 14, 29, 44 and 59 minutes every hour of everyday
*/5 * * * * ==> Every 5 minutes

Now that you know where to add your cron job command, let’s go through two simple ways to set it up.

Magento Cron Job Using WGET

*/5 * * * * wget -q

Magento Cron Job Using PHP

*/5 * * * * /path/to/php -f /local/path/to/cron.php

Testing The Magento Cron Jobs

It is difficult to test that the Magento cron jobs are now set up correctly without waiting a couple of days and seeing whether your indexes have been refreshed. Fortunately, there is a quick test you can perform to tell. Change your cron tab command to one of the following (depending on the method you chose).

[email protected]
*/5 * * * * wget-bad-command -q
[email protected]
*/5 * * * * /path/to/php -f /local/path/to/cron-bad-filename.php

More examples

# run at 10 pm on weekdays, 
0 22 * * 1-5   mail -s "It's 10pm" ken%Ken,%%Where is food?%
23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
5 4 * * sun     echo "run at 5 after 4 every sunday"

Magento online customer shows instead of real IP address

Tuesday, 10. April 2012

Came across this issue today when client mentioned after the move to new server all of a sudden all online customers IP address were showing as instead of their correct IP address.

This is a proxy issue and the best solution lies within the local.xml.additional file.

Basically you will need this snippet text below added to you local.xml file just before the closing of the tag


Make sure you FLUSH MAGENTO CACHE to see changes.

Enjoy :)