Tuesday, September 20, 2011

Checking what files to checkin in SVN

Coming from rational Clearcase background, I always like to check which files I need to checkin and which files I would like to revert back.

First I check all files that have been added but not necessarily been added into the svn archive.
svn status | grep "^?" | awk '{ print $2} 

For the files that need to achieved do this manually.  For all other files you should save these in a tar and delete them. Most often these are files
svn status | grep "^?" | awk '{ print $2} >not-needed.txt

At this point you may want to remove the directories which are cached or not under source control

tar cxvfa  not-needed.tgz -T not-need.txt 
cat not-needed.txt | xarags rm -rf $1

Finally for all files that are now modified, I like to make sure they are really needed. Do a diff and make sure the code is correct.

svn status | grep "^[AM]" | awk '{if ($2=="S" || $2=="+") print $3; else print $2;}'

Sunday, September 11, 2011

In magento I have been jumping over all the directories to be able to see the code. Half my life was being spent on CDing.

Then I found this easy script

Basically it allows you to do a save on any alias and then go to the alias.

The script is basically very simple and can be easily used in any bash shell by adding it to .bashrc or .bash_aliases (for sake of completion)

# Bash Directory Bookmarks
alias m1='alias g1="cd `pwd`"'
alias m2='alias g2="cd `pwd`"'
alias m3='alias g3="cd `pwd`"'
alias m4='alias g4="cd `pwd`"'
alias m5='alias g5="cd `pwd`"'
alias m6='alias g6="cd `pwd`"'
alias m7='alias g7="cd `pwd`"'
alias m8='alias g8="cd `pwd`"'
alias m9='alias g9="cd `pwd`"'
alias mdump='alias|grep -e "alias g[0-9]"|grep -v "alias m" > ~/.bookmarks'
alias lma='alias | grep -e "alias g[0-9]"|grep -v "alias m"|sed "s/alias //"'

However there is now a better script which helps you save the names in more readable format and then go to that. For that you should look up the script yourself.

Magento: How to change Title, Sescription and Keywords in static pages

Magento is fairly SEO friendly but for certain pages, it does not allow you to change the Title, Description or the keywords. Some of these pages are very important for Google crawls such as Search terms, Advanced search, Contact us, Sitemaps etc. There are other pages such as accounts etc, which also set the default keywords, however I do not care if they are crawled by Google as they are customer specific.

You can set all of these by making simple changes the layout XML files and the block functional file.
We have to create the functions setDescription and setKeywords in .../app/code/core/Mage/Page/Block/Html/Head.php  (Remember it always best to make a copy of this file in .../app/code/local/Mage/Page/Block/Html/Head.php).

     * Set description element text
     * @param string $description
     * @return Mage_Page_Block_Html_Head
    public function setDescription($description)
        $this->_data['description'] = $description;
        return $this;

     * Set Keywords element text
     * @param string $keywords
     * @return Mage_Page_Block_Html_Head
    public function setKeywords($keywords)
        $this->_data['keywords'] = $keywords;
        return $this;

Let us take Advanced Search for example and see how we can make these changes. In layout/catalogsearch.xml

 After <label>Advanced Search Form</label>
        <reference name="head">
        <action method="setForcedTitle"><title>%TITLE%Vyom search</title></action>
        <action method="setDescription"><description>%DESCRIPTION%</description></action>
        <action method="setKeywords"><keywords>%KEYWORDS%</keywords></action>

Make sure you clear your cache before checking the changes. Similarly, find the right XML file and whichever static page you want to make the changes. 

Thursday, September 8, 2011

Magento: Out of stock pushed to the end of the list

Magento allows sorting by Position, Price and Name in the toolbar.

But It does not look at the status of product and if the product is available. Under normal circumstances, I would not like to show any of the products which are not available but due to SEO reasons, it makes sense to continue showing the products. So I would like to continue showing the products based on one of the sorting method but pushing the out-of-stock product at the end.

To do this a good post is http://www.magentocommerce.com/boards/viewthread/203590/#t345652

A more elegant solution is to make changes in .../Mage/Catalog/Model/Layer.php at line #102
$collection->joinField('inventory_in_stock', 'cataloginventory_stock_item', 'is_in_stock', 'product_id=entity_id','is_in_stock>=0', 'left')->setOrder('inventory_in_stock', 'desc');

This will effect both the listing as well as the results page.

Another things is to remember to copy this file from core to code/local//Mage/Catalog/Model/Layer.php so that the core files remain as it is.

Ricardo Martins has made this into a github project and posted the code on

I have not checked the code but it will be helpful for lot of folks. Thanks Ricardo

Wednesday, September 7, 2011

Putty screen freeze due to CTRL-S

Over the last couple of day, I faced a problem of getting screen freezes while I was working on vi. It became very frustrating as I had to restart my putty and also remove the swap file.

I finally realised that the reason was I was pressing CTLR-S for saving a file out of sheer habit. CTLR-S on bash generally means XOFF (output off) and you need to do a CTLR-Q to turn it back on.

Instead of that a simple addition to .bash_profile can save you the trouble.
stty -ixon

However even with this I was getting a statment such as i-search when I would type CTLR-S.
For that I removed the binding from my bash shell. 
bind -r '\C-s'

So all in all the changes need in your .bash_profile is
bind -r '\C-s'
stty -ixon