Wednesday, October 5, 2011

Mangento exporting SQL issue

While exporting mySQL if you every get into the problem]


ERROR 1064 (42000) at line 688: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'USING BTREE,
  KEY `FK_ATTRIBUTE_VARCHAR_ENTITY` (`entity_id`),
  KEY `FK_CATALO' at line 9

and the mySQL is 
UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`) USING BTREE

You need to replace all such instance by 

UNIQUE KEY `IDX_BASE` USING BTREE(`entity_type_id`,`entity_id`,`attribute_id`,`store_id`)

Tuesday, October 4, 2011

How to making Linux multihomed to connect to 2 ISP

To make my Ubuntu Server on more robust I have connected it to 2 ISP so that I can have redundant last mile. Also one of my ISP gives me unlimited bandwidth while the other is costlier but more reliable.

1.
To make your linux server multihomed, I am assuming that you have atleast 2 network interfaces. In my case both are ethernet (eth0 and eth1)

2. 
Make sure both the networks are working individually up by setting it on /etc/network/interface
sudo vi /etc/network/interface

#Loopback
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
        address 192.168.200.100
        netmask 255.255.255.0
        metric 100
        gateway 192.168.200.6

auto eth1
iface eth1 inet static
        address 192.168.201.100
        netmask 255.255.255.0
        metric 200
        gateway 192.168.201.5

Now if you go to your terminal, you should be able to
>ip route show
192.168.201.0/24 dev eth1  proto kernel  scope link  src 192.168.201.100
192.168.200.0/24 dev eth0  proto kernel  scope link  src 192.168.200.100
default via 192.168.200.6 dev eth0  metric 100
default via 192.168.201.5 dev eth1  metric 200

With this if your eth0 goes down, your eth1 will take over and vice-versa.
But this is still a long way from making your network multihoned where your can do load balancing.

All you need to do is to add  multihop route in your /etc/rc.local
ip route append default scope global nexthop via 192.168.200.6 dev eth0 weight 5 nexthop via 192.168.201.5 dev eth1 weight 1

USB for Ubuntu Server

Ubuntu Server does not come with auto-mount for USB.
You will need to install the light weight usbmount

sudo apt-get install usbmount

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
http://www.huyng.com/archives/quick-bash-tip-directory-bookmarks/492/

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.
http://www.huyng.com/bashmarks-directory-bookmarks-for-the-shell/


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.
1.
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;
    }



2. 
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>
        </reference>


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.