ajaxaddress - Version 1.0.0

Version Notes

First Release

Download this release

Release Info

Developer Chandan Kumar Singh
Extension ajaxaddress
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Chandan/Ajaxaddress/Block/Ajaxaddress.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Chandan_Ajaxaddress_Block_Ajaxaddress extends Mage_Checkout_Block_Onepage
3
+ {
4
+
5
+ }
app/code/community/Chandan/Ajaxaddress/Helper/Data.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class Chandan_Ajaxaddress_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ }
app/code/community/Chandan/Ajaxaddress/controllers/AjaxaddressController.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Chandan_Ajaxaddress_AjaxaddressController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ function getCityState($zip, $blnUSA = true) {
5
+ $url = "http://maps.googleapis.com/maps/api/geocode/json?address=" . $zip . "&sensor=true";
6
+ $address_info = file_get_contents($url);
7
+ $json = json_decode($address_info);
8
+ $city = "";
9
+ $state = "";
10
+ $country = "";
11
+ if (count($json->results) > 0) {
12
+ $arrComponents = $json->results[0]->address_components;
13
+ foreach($arrComponents as $index=>$component) {
14
+ $type = $component->types[0];
15
+ if ($city == "" && ($type == "sublocality_level_1" || $type == "locality") ) {
16
+ $city = trim($component->short_name);
17
+ }
18
+ if ($country == "" && $type=="country") {
19
+ $country = trim($component->short_name);
20
+ }
21
+ if ($state == "" && $type=="administrative_area_level_1") {
22
+ $state = trim($component->short_name);
23
+ $collection = Mage::getModel('directory/region')->getResourceCollection()->addCountryFilter($country)->load();
24
+ $count = $collection->getData();
25
+ foreach($collection as $region) {
26
+ if($region["code"] == $state)
27
+ {
28
+ $state_code = $region["region_id"];
29
+ break;
30
+ }
31
+ }
32
+ }
33
+
34
+ if ($city != "" && $state != "" && $country != "") {
35
+ break;
36
+ }
37
+ }
38
+ }
39
+ $arrReturn = array("city"=>$city, "state"=>$state_code, "country"=>$country);
40
+ die(json_encode($arrReturn));
41
+ }
42
+
43
+ public function ajaxregionAction(){
44
+ $zip = $this->getRequest()->getParam('zip');
45
+ echo $this->getCityState($zip);
46
+ die;
47
+ }
48
+
49
+
50
+ public function countryselectAction(){
51
+ $countryid = $this->getRequest()->getParam('country');
52
+ $collection = Mage::getModel('directory/region')->getResourceCollection()->addCountryFilter($countryid)->load();
53
+ $count = $collection->getData();
54
+
55
+ if(!empty($count)) {
56
+ echo '<option value="">Please Select</option>';
57
+ foreach($collection as $region) {
58
+ echo '<option value='.$region["region_id"].'>'.$region["default_name"].'</option>';
59
+ }
60
+ } else {
61
+ echo '<input type="text" id="billing:region_id" name="billing[region_id]" title="State/Province" class="input-text">';
62
+ }
63
+ }
64
+ }
app/code/community/Chandan/Ajaxaddress/etc/config.xml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Chandan_Ajaxaddress>
5
+ <version>1.0.0</version>
6
+ </Chandan_Ajaxaddress>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <checkout>
11
+ <rewrite>
12
+ <onepage>Chandan_Ajaxaddress_Block_Ajaxaddress</onepage>
13
+ </rewrite>
14
+ </checkout>
15
+ </blocks>
16
+ <helpers>
17
+ <chandan_ajaxaddress>
18
+ <class>Chandan_Ajaxaddress_Helper</class>
19
+ </chandan_ajaxaddress>
20
+ </helpers>
21
+ </global>
22
+ <frontend>
23
+ <routers>
24
+ <ajaxaddress>
25
+ <use>standard</use>
26
+ <args>
27
+ <module>Chandan_Ajaxaddress</module>
28
+ <frontName>ajaxaddress</frontName>
29
+ </args>
30
+ </ajaxaddress>
31
+ </routers>
32
+ <layout>
33
+ <updates>
34
+ <ajaxaddress>
35
+ <file>ajaxaddress.xml</file>
36
+ </ajaxaddress>
37
+ </updates>
38
+ </layout>
39
+ </frontend>
40
+ </config>
app/design/frontend/base/default/layout/ajaxaddress.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+
4
+ <checkout_onepage_index>
5
+ <reference name="checkout.onepage">
6
+ <action method="setTemplate"><template>ajaxaddress\checkout\onepage.phtml</template></action>
7
+ </reference>
8
+ </checkout_onepage_index>
9
+
10
+ </layout>
app/design/frontend/base/default/template/ajaxaddress/checkout/onepage.phtml ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magento.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magento.com for more information.
20
+ *
21
+ * @category design
22
+ * @package rwd_default
23
+ * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <div class="page-title">
28
+ <h1><?php echo $this->__('Checkout') ?></h1>
29
+ </div>
30
+ <script type="text/javascript" src="<?php echo $this->getJsUrl('varien/accordion.js') ?>"></script>
31
+ <script type="text/javascript" src="<?php echo $this->getSkinUrl('js/opcheckout.js') ?>"></script>
32
+ <script type="text/javascript" src="<?php echo $this->getSkinUrl('js/opcheckout_rwd.js') ?>"></script>
33
+ <ol class="opc opc-firststep-<?php echo $this->getActiveStep() ?>" id="checkoutSteps">
34
+ <?php $i=0; foreach($this->getSteps() as $_stepId => $_stepInfo): ?>
35
+ <?php if (!$this->getChild($_stepId) || !$this->getChild($_stepId)->isShow()): continue; endif; $i++ ?>
36
+ <li id="opc-<?php echo $_stepId ?>" class="section<?php echo !empty($_stepInfo['allow'])?' allow':'' ?><?php echo !empty($_stepInfo['complete'])?' saved':'' ?>">
37
+ <div class="step-title">
38
+ <span class="number"><?php echo $i ?></span>
39
+ <h2><?php echo $_stepInfo['label'] ?></h2>
40
+ <a href="#"><?php echo $this->__('Edit') ?></a>
41
+ </div>
42
+ <div id="checkout-step-<?php echo $_stepId ?>" class="step a-item" style="display:none;">
43
+ <?php echo $this->getChildHtml($_stepId) ?>
44
+ </div>
45
+ </li>
46
+ <?php endforeach ?>
47
+ </ol>
48
+ <script type="text/javascript">
49
+ //<![CDATA[
50
+ var accordion = new Accordion('checkoutSteps', '.step-title', true);
51
+ <?php if($this->getActiveStep()): ?>
52
+ accordion.openSection('opc-<?php echo $this->getActiveStep() ?>');
53
+ <?php endif ?>
54
+ var checkout = new Checkout(accordion,{
55
+ progress: '<?php echo $this->getUrl('checkout/onepage/progress') ?>',
56
+ review: '<?php echo $this->getUrl('checkout/onepage/review') ?>',
57
+ saveMethod: '<?php echo $this->getUrl('checkout/onepage/saveMethod') ?>',
58
+ failure: '<?php echo $this->getUrl('checkout/cart') ?>'}
59
+ );
60
+ //]]>
61
+
62
+
63
+
64
+
65
+ jQuery(function() {
66
+ var zipcode = jQuery('#billing-new-address-form .validate-zip-international').val();
67
+ jQuery('#billing-new-address-form .validate-zip-international').blur(function() {
68
+ if (jQuery('#billing-new-address-form .validate-zip-international').val() != zipcode) {
69
+
70
+ zip = jQuery('#billing-new-address-form .validate-zip-international').val();
71
+ jQuery.ajax({
72
+ url: "<?php echo $this->getUrl(); ?>ajaxaddress/ajaxaddress/ajaxregion/",
73
+ data: { zip: zip },
74
+ type:"POST",
75
+ success:function(html){
76
+ var objData = jQuery.parseJSON(html);
77
+ country = objData .country;
78
+ jQuery.ajax({
79
+ url: "<?php echo $this->getUrl(); ?>ajaxaddress/ajaxaddress/countryselect",
80
+ data: {country:country},
81
+ type:"POST",
82
+ success:function(html){
83
+ var region = jQuery('#billing\\:region_id');
84
+ region.empty();
85
+ region.append(html);
86
+ jQuery('#billing\\:region_id').val(objData .state);
87
+ }
88
+ });
89
+ jQuery('#billing\\:country_id').val(objData .country);
90
+ jQuery('#billing\\:city').val(objData .city);
91
+ }
92
+ });
93
+ }
94
+ });
95
+ });
96
+
97
+
98
+ jQuery(function() {
99
+ var zipcode = jQuery('#shipping-new-address-form .validate-zip-international').val();
100
+ jQuery('#shipping-new-address-form .validate-zip-international').blur(function() {
101
+ if (jQuery('#shipping-new-address-form .validate-zip-international').val() != zipcode) {
102
+ zip = jQuery('#shipping-new-address-form .validate-zip-international').val();
103
+ jQuery.ajax({
104
+ url: "<?php echo $this->getUrl(); ?>ajaxaddress/ajaxaddress/ajaxregion/",
105
+ data: { zip: zip },
106
+ type:"POST",
107
+ success:function(html){
108
+ var objData = jQuery.parseJSON(html);
109
+ country = objData .country;
110
+ jQuery.ajax({
111
+ url: "<?php echo $this->getUrl(); ?>ajaxaddress/ajaxaddress/countryselect",
112
+ data: {country:country},
113
+ type:"POST",
114
+ success:function(html){
115
+ var region = jQuery('#shipping\\:region_id');
116
+ region.empty();
117
+ region.append(html);
118
+ jQuery('#shipping\\:region_id').val(objData .state);
119
+ }
120
+ });
121
+ jQuery('#shipping\\:country_id').val(objData .country);
122
+ jQuery('#shipping\\:city').val(objData .city);
123
+ }
124
+ });
125
+ }
126
+ });
127
+ });
128
+
129
+ </script>
app/etc/modules/Chandan_Ajaxaddress.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Chandan_Ajaxaddress>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Chandan_Ajaxaddress>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>ajaxaddress</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="https://opensource.org/licenses/osl-3.0.php">OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Ajaxaddress</summary>
10
+ <description>Ajaxaddress</description>
11
+ <notes>First Release</notes>
12
+ <authors><author><name>Chandan Kumar Singh</name><user>chandan8050</user><email>chandankumar8050@gmail.com</email></author></authors>
13
+ <date>2017-01-23</date>
14
+ <time>16:04:05</time>
15
+ <contents><target name="magecommunity"><dir name="Chandan"><dir name="Ajaxaddress"><dir name="Block"><file name="Ajaxaddress.php" hash="a6db9e49d47cb2e597079456f68d750d"/></dir><dir name="Helper"><file name="Data.php" hash="a515ff10b1b39beee37101a74bb697ad"/></dir><dir name="controllers"><file name="AjaxaddressController.php" hash="6ea6cabddf4d1670bd9e2f49970878a2"/></dir><dir name="etc"><file name="config.xml" hash="3f086070ed08c9271829125755b4bfd4"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Chandan_Ajaxaddress.xml" hash="42435c9b006dedb6b70724032cac80c6"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="ajaxaddress.xml" hash="222733e5f8e6a9209e1a868475f496ba"/></dir><dir name="template"><dir name="ajaxaddress"><dir name="checkout"><file name="onepage.phtml" hash="26d49d77e5d826fb9d0e7a0915089b55"/></dir></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>7.1.0</max></php></required></dependencies>
18
+ </package>