0

I am searching the way to add three dropdowns into checkout page but still, I did not get any way to do this.

0
3

Adding the list of States in India to Magento

I have tested this and worked for me on my server.

Please open your php my admin and run following:

INSERT INTO directory_country_region VALUES
(NULL , "IN", "Andaman and Nicobar","Andaman and Nicobar"),
(NULL , "IN", "Andhra Pradesh","Andhra Pradesh"),
(NULL , "IN", "Arunachal Pradesh","Arunachal Pradesh"),
(NULL , "IN", "Assam","Assam"),
(NULL , "IN", "Bihar","Bihar"),
(NULL , "IN", "Chandigarh","Chandigarh"),
(NULL , "IN", "Chhattisgarh","Chhattisgarh"),
(NULL , "IN", "Dadra and Nagar Haveli","Dadra and Nagar Haveli"),
(NULL , "IN", "Daman and Diu","Daman and Diu"),
(NULL , "IN", "Delhi","Delhi"),
(NULL , "IN", "Goa","Goa"),
(NULL , "IN", "Gujarat","Gujarat"),
(NULL , "IN", "Haryana","Haryana"),
(NULL , "IN", "Himachal Pradesh","Himachal Pradesh"),
(NULL , "IN", "Jammu and Kashmir","Jammu and Kashmir"),
(NULL , "IN", "Jharkhand","Jharkhand"),
(NULL , "IN", "Karnataka","Karnataka"),
(NULL , "IN", "Kerala","Kerala"),
(NULL , "IN", "Lakshadweep","Lakshadweep"),
(NULL , "IN", "Madhya Pradesh","Madhya Pradesh"),
(NULL , "IN", "Maharashtra","Maharashtra"),
(NULL , "IN", "Manipur","Manipur"),
(NULL , "IN", "Meghalaya","Meghalaya"),
(NULL , "IN", "Mizoram","Mizoram"),
(NULL , "IN", "Nagaland","Nagaland"),
(NULL , "IN", "Orissa","Orissa"),
(NULL , "IN", "Pondicherry","Pondicherry"),
(NULL , "IN", "Punjab","Punjab"),
(NULL , "IN", "Rajasthan","Rajasthan"),
(NULL , "IN", "Sikkim","Sikkim"),
(NULL , "IN", "Tamil Nadu","Tamil Nadu"),
(NULL , "IN", "Tripura","Tripura"),
(NULL , "IN", "Uttar Pradesh","Uttar Pradesh"),
(NULL , "IN", "Uttaranchal","Uttaranchal"),
(NULL , "IN", "West Bengal","West Bengal");

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

I hope it will help to you.

http://tejabhagavan.blogspot.in/2015/12/adding-list-of-states-in-india-to.html

Adding the list of Cities in India to Magento

Please follow this url to get the city drop down.http://www.magebuzz.com/region-city-manager.html

2
  • 1
    Thanks for your reply..But I want to add three dropdown state, city and locality. I am adding html in billing.phtml but it is not showing on frontend.
    – Virat
    Aug 12 '16 at 6:13
  • My site two years old, just now i updates above command when i go to checkout, for all users asking the select state, but we know customer state, how can i assign the state to the customer for 100k customers.
    – Gem
    Apr 19 '18 at 9:00
1

For state dropdown, Refer "https://tejabhagavan.blogspot.in/2015/12/adding-list-of-states-in-india-to.html" and add states accordingly your country.

You have to create two more tables in the database.

for city dropdown. Let's say "directory_country_region_city" having four columns as below.

  1. city_id (INT, primary key, autoincrement) 2 country_id (VARCHAR) values like IN,US,UK.
  2. region_id (FK, INT, id from "directory_country_region" tables).
  3. city_name (varchar) Name of the city according to Country, region_id.

for locality dropdown. Let's say "directory_city_region" having four columns as below.

  1. locality_id.
  2. city_id. (FK of directory_country_region_city)
  3. locality_name.

Create manully script to import cities and locality data in both tables.

Now in the billing and shipping html, you just need to add two dropdowns. for city and locality.

Now on change of state, write ajax and point to controller which fetches cities according to selected country and region id.

same as for locality write ajax and point to a controller which fetches localities according to selected city_id.

the controller code should be as below.

public function getcitiesAction()
{
    if (!$this->getRequest()->isXmlHttpRequest()) {
        return;
    }

    $regionId = (int)$this->getRequest()->getParam('region_id');
    $countryId = $this->getRequest()->getParam('country_id');

    if (!$regionId || !$countryId) {
        return;
    }

    echo Mage::helper('your data helper')->getCities($countryId, $regionId);

    return;
}

 public function getLocalityAction()
{
    if (!$this->getRequest()->isXmlHttpRequest()) {
        return;
    }

    $cityId = (int)$this->getRequest()->getParam('city_id');


    if (!cityId ) {
        return;
    }

    echo Mage::helper('your data helper')->getlocalities($cityId);

    return;
}

============Helper function=====================

public function getCities($countryId, $regionId)
{
    $cityCollection = Mage::getModel('your city model')->getCollection();
        $cityCollection->addFieldToSelect('cityname')
        ->addFieldToFilter('country_id', $countryId)
        ->addFieldToFilter('region_id', $regionId);

    $jsonData = Mage::helper('core')->jsonEncode($cityCollection->getData());

    return $jsonData;
}


public function getlocalities($cityId)
{
    $localityCollection = Mage::getModel('your locality model')->getCollection();
        $cityCollection->addFieldToSelect('locality_name')
        ->addFieldToFilter('city_id', $cityId)


    $jsonData = Mage::helper('core')->jsonEncode($localityCollection ->getData());

    return $jsonData;
}

Now create one js file and add ajax function which returns data of city and locality in JSON format and set data in city and locality drop-down option.

hope it helps.

Not the answer you're looking for? Browse other questions tagged or ask your own question.