Get customer last order in Magento.

$_customer = Mage::getModel('customer/customer');

$_customer->loadByEmail('customer_email@yoursitedomain.com');
$orders = Mage::getResourceModel('sales/order_collection')
->addFieldToSelect('*')
->addFieldToFilter('customer_id', $_customer->getId())
->addAttributeToSort('created_at', 'DESC')
->setPageSize(1);

echo $orders->getFirstItem()->getId();

How to add list of India states drop-down in Magento?

If you’re setting up a Magento store for India, you’ll notice that in Magento admin panel does not provide a way to modify the list of states for a country. By using below steps you can easily get your work done:

We have two tables in database which stores the region details

  1. directory_country_region.
  2. directory_country_region_name.

When we add record to directory_country_region it will enable the selectbox for the country we have added and we have the options to make the region required too. Then we have to add the desired regions to the second table directory_country_region_name.

Step 1:

First magento save region list at directory_country_region table: So insert new region list on with respective country in this table: directory_country_region

Run the below query:

INSERT INTO `directory_country_region` VALUES
(NULL , 'IN', 'AN','Andaman and Nicobar Islands'),
(NULL , 'IN', 'AP','Andhra Pradesh'),
(NULL , 'IN', 'AR','Arunachal Pradesh'),
(NULL , 'IN', 'AS','Assam'),
(NULL , 'IN', 'BR','Bihar'),
(NULL , 'IN', 'CH','Chandigarh'),
(NULL , 'IN', 'CT','Chhattisgarh'),
(NULL , 'IN', 'DN','Dadra and Nagar Haveli'),
(NULL , 'IN', 'DD','Daman and Diu'),
(NULL , 'IN', 'DL','Delhi'),
(NULL , 'IN', 'GA','Goa'),
(NULL , 'IN', 'GJ','Gujarat'),
(NULL , 'IN', 'HR','Haryana'),
(NULL , 'IN', 'HP','Himachal Pradesh'),
(NULL , 'IN', 'JK','Jammu and Kashmir'),
(NULL , 'IN', 'JH','Jharkhand'),
(NULL , 'IN', 'KA','Karnataka'),
(NULL , 'IN', 'KL','Kerala'),
(NULL , 'IN', 'LD','Lakshadweep'),
(NULL , 'IN', 'MP','Madhya Pradesh'),
(NULL , 'IN', 'MH','Maharashtra'),
(NULL , 'IN', 'MN','Manipur'),
(NULL , 'IN', 'ML','Meghalaya'),
(NULL , 'IN', 'MZ','Mizoram'),
(NULL , 'IN', 'NL','Nagaland'),
(NULL , 'IN', 'OR','Odisha'),
(NULL , 'IN', 'PY','Puducherry'),
(NULL , 'IN', 'PB','Punjab'),
(NULL , 'IN', 'RJ','Rajasthan'),
(NULL , 'IN', 'SK','Sikkim'),
(NULL , 'IN', 'TN','Tamil Nadu'),
(NULL , 'IN', 'TG','Telangana'),
(NULL , 'IN', 'TR','Tripura'),
(NULL , 'IN', 'UP','Uttar Pradesh'),
(NULL , 'IN', 'UT','Uttarakhand'),
(NULL , 'IN', 'WB','West Bengal');

Step 2: Also you need insert directory_country_region_name for language wish region name.

as default indian people is use en_us (language code) as default language

Using below query:

INSERT INTO directory_country_region_name( locale, region_id, name )
SELECT 'en_US' AS "language", region_id, default_name
FROM `directory_country_region`
WHERE country_id = 'IN';

If you are not interested in manual way, then there are extensions availbale in magento connect in which one of them is free Regions Manager

Quick Magento installation with or without sample data using SSH

In this article, we will know how to install the most recent Magento versions using the code via SSH. This will also include the process of Magento installation with or without sample data.

Below mentioned are some of the ways to download Magento with SSH: Copy and paste these commands into the ssh command line.

Magento Setup without sample data:

wget http://www.magentocommerce.com/downloads/assets/1.7.0.2/magento-1.7.0.2.tar.gz

tar -zxvf magento-1.7.0.2.tar.gz

mv magento/* magento/.htaccess .

chmod -R o+w media var

chmod o+w app/etc

Along with the setup, we have to delete the downloaded file and empty the directory from the extracted files:

rm -rf magento/ magento-1.7.0.2.tar.gz

Magento Setup with Sample Data:

wget http://www.magentocommerce.com/downloads/assets/1.7.0.2/magento-1.7.0.2.tar.gz

tar -zxvf magento-1.7.0.2.tar.gz

wget http://www.magentocommerce.com/downloads/assets/1.6.1.0/magento-sample-data-1.6.1.0.tar.gz

tar -zxvf magento-sample-data-1.6.1.0.tar.gz

mv magento-sample-data-1.6.1.0/media/* magento/media/

mv magento-sample-data-1.6.1.0/magento_sample_data_for_1.6.1.0.sql magento/data.sql

mv magento/* magento/.htaccess* .

chmod -R o+w media var

mysql -h DBHOST -u DBUSER -pDBPASS DBNAME < data.sql

chmod o+w var var/.htaccess app/etc

rm -rf magento/ magento-sample-data-1.6.1.0/ magento-1.7.0.2.tar.gz magento-sample-data-1.6.1.0.tar.gz data.sql

Note: please add replace this with real values: DBHOST, DBNAME, DBUSER and DBPASS.

Finishing the Installation via Web Based Installer:

After you have installed Magento via SSH, you can proceed through the web-based installer. You’ll use the same database details in that as well.