Curkle-Magento-addressAutoComplete - Version 0.1.4

Version Notes

https://github.com/curkle/Magento-addressAutoComplete

Download this release

Release Info

Developer Curkle Inc
Extension Curkle-Magento-addressAutoComplete
Version 0.1.4
Comparing to
See all releases


Code changes from version 0.1.3 to 0.1.4

app/code/local/Curkle/AddressAutoComplete/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Curkle_AddressAutoComplete>
5
- <version>0.1.2</version>
6
  </Curkle_AddressAutoComplete>
7
  </modules>
8
  <frontend>
@@ -14,6 +14,15 @@
14
  </updates>
15
  </layout>
16
  </frontend>
 
 
 
 
 
 
 
 
 
17
  <global>
18
  <helpers>
19
  <addressautocomplete>
2
  <config>
3
  <modules>
4
  <Curkle_AddressAutoComplete>
5
+ <version>0.1.4</version>
6
  </Curkle_AddressAutoComplete>
7
  </modules>
8
  <frontend>
14
  </updates>
15
  </layout>
16
  </frontend>
17
+ <adminhtml>
18
+ <layout>
19
+ <updates>
20
+ <addressautocomplete>
21
+ <file>addressautocomplete.xml</file>
22
+ </addressautocomplete>
23
+ </updates>
24
+ </layout>
25
+ </adminhtml>
26
  <global>
27
  <helpers>
28
  <addressautocomplete>
app/design/frontend/default/default/layout/addressautocomplete.xml CHANGED
@@ -8,6 +8,7 @@
8
  </action>
9
  </block>
10
  <action method="addItem"><type>skin_js</type><name>js/addressautocomplete/onstepcheckout.js</name></action>
 
11
  </reference>
12
  </checkout_onepage_index>
13
  <firecheckout_index_index> <!--Firecheckout adding -->
@@ -18,6 +19,7 @@
18
  </action>
19
  </block>
20
  <action method="addItem"><type>skin_js</type><name>js/addressautocomplete/onstepcheckout.js</name></action>
 
21
  </reference>
22
  </firecheckout_index_index>
23
  </layout>
8
  </action>
9
  </block>
10
  <action method="addItem"><type>skin_js</type><name>js/addressautocomplete/onstepcheckout.js</name></action>
11
+ <action method="addItem"><type>skin_js</type><name>js/addressautocomplete/onstepcheckout_shipping.js</name></action>
12
  </reference>
13
  </checkout_onepage_index>
14
  <firecheckout_index_index> <!--Firecheckout adding -->
19
  </action>
20
  </block>
21
  <action method="addItem"><type>skin_js</type><name>js/addressautocomplete/onstepcheckout.js</name></action>
22
+ <action method="addItem"><type>skin_js</type><name>js/addressautocomplete/onstepcheckout_shipping.js</name></action>
23
  </reference>
24
  </firecheckout_index_index>
25
  </layout>
app/etc/modules/Curkle_AddressAutoComplete.xml CHANGED
@@ -4,7 +4,7 @@
4
  <Curkle_AddressAutoComplete>
5
  <active>true</active>
6
  <codePool>local</codePool>
7
- <version>0.1.2</version>
8
  </Curkle_AddressAutoComplete>
9
  </modules>
10
  </config>
4
  <Curkle_AddressAutoComplete>
5
  <active>true</active>
6
  <codePool>local</codePool>
7
+ <version>0.1.4</version>
8
  </Curkle_AddressAutoComplete>
9
  </modules>
10
  </config>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Curkle-Magento-addressAutoComplete</name>
4
- <version>0.1.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
  <channel>community</channel>
@@ -21,9 +21,9 @@ for more detail.&#xD;
21
  </description>
22
  <notes>https://github.com/curkle/Magento-addressAutoComplete</notes>
23
  <authors><author><name>Curkle Inc</name><user>Vincent</user><email>vincent@curkle.com</email></author></authors>
24
- <date>2015-02-09</date>
25
- <time>21:08:35</time>
26
- <contents><target name="magelocal"><dir><dir name="Curkle"><dir name="AddressAutoComplete"><dir name="Helper"><file name="Data.php" hash="4b5a3add62ee4675a26d55401f73e3ab"/></dir><dir name="etc"><file name="config.xml" hash="d54d81d0d4c65fae13d7b30fc82c512e"/></dir></dir></dir></dir></target><target name="magedesign"><dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="addressautocomplete.xml" hash="2bdb43e6883c943502c06d8999cf7599"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Curkle_AddressAutoComplete.xml" hash="8f5bcdc33e325b6ce6e3fedb6461aeb7"/></dir></dir></target><target name="mageskin"><dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="js"><dir name="addressautocomplete"><file name="onstepcheckout.js" hash="65c97e67ab1b8b38ef06ae49c2cde274"/></dir></dir></dir></dir></dir></dir></target></contents>
27
  <compatible/>
28
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
29
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Curkle-Magento-addressAutoComplete</name>
4
+ <version>0.1.4</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
  <channel>community</channel>
21
  </description>
22
  <notes>https://github.com/curkle/Magento-addressAutoComplete</notes>
23
  <authors><author><name>Curkle Inc</name><user>Vincent</user><email>vincent@curkle.com</email></author></authors>
24
+ <date>2015-05-05</date>
25
+ <time>14:33:14</time>
26
+ <contents><target name="magelocal"><dir><dir name="Curkle"><dir name="AddressAutoComplete"><dir name="Helper"><file name="Data.php" hash="4b5a3add62ee4675a26d55401f73e3ab"/></dir><dir name="etc"><file name="config.xml" hash="4f6bc617bc18f21bed05a54856a0f745"/></dir></dir></dir></dir></target><target name="magedesign"><dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="addressautocomplete.xml" hash="2cad3dcb4d3b0104685c9b166b4d90e4"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Curkle_AddressAutoComplete.xml" hash="3a0d921d9c75d7b9769c9ce0f615bd34"/></dir></dir></target><target name="mageskin"><dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="js"><dir name="addressautocomplete"><file name="map.js" hash="b96dd9dd31ca6e3ad9d4c8e1ff4db617"/><file name="onstepcheckout.js" hash="65c97e67ab1b8b38ef06ae49c2cde274"/><file name="onstepcheckout_shipping.js" hash="aeb2d90982a8ae60506fad5c592f8859"/></dir></dir></dir></dir></dir></dir></target></contents>
27
  <compatible/>
28
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
29
  </package>
skin/frontend/base/default/js/addressautocomplete/map.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ function loadScript() {
2
+ var script = document.createElement('script');
3
+ script.type = 'text/javascript';
4
+ script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp' +
5
+ '&signed_in=true&callback=initialize';
6
+ document.body.appendChild(script);
7
+ }
8
+
9
+ window.onload = loadScript;
skin/frontend/base/default/js/addressautocomplete/onstepcheckout_shipping.js ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This example displays an address form, using the autocomplete feature
2
+ // of the Google Places API to help users fill in the information.
3
+ // for shipping
4
+ "use strict";
5
+ var CURKLEAUTOCOMPLETE_SHIPPING = CURKLEAUTOCOMPLETE_SHIPPING || {};
6
+
7
+ CURKLEAUTOCOMPLETE_SHIPPING.event = {};
8
+ CURKLEAUTOCOMPLETE_SHIPPING.method = {
9
+ placeSearch: "", //
10
+ IdSeparator: "", //
11
+ autocomplete : "",
12
+ streetNumber : "",
13
+ formFields : {
14
+ 'street1': '',
15
+ 'street2': '',
16
+ 'city': '',
17
+ // 'region': '',
18
+ 'postcode': '',
19
+ 'region_id' : ''
20
+ },
21
+ formFieldsValue : {
22
+ 'street1': '',
23
+ 'street2': '',
24
+ 'city': '',
25
+ // 'region': '',
26
+ 'postcode': '',
27
+ 'region_id' : ''
28
+ },
29
+ component_form : "",
30
+
31
+ initialize: function(){
32
+ //init form
33
+ this.getIdSeparator();
34
+ this.initFormFields();
35
+
36
+ this.autocomplete = new google.maps.places.Autocomplete(
37
+ /** @type {HTMLInputElement} */(document.getElementById('shipping:street1')),
38
+ { types: ['geocode']});
39
+ // When the user selects an address from the dropdown,
40
+ // populate the address fields in the form.
41
+ google.maps.event.addListener(this.autocomplete, 'place_changed', function( event ) {CURKLEAUTOCOMPLETE_SHIPPING.method.fillInAddress()});
42
+ var shipping_address = document.getElementById("shipping:street1");
43
+ if(shipping_address != null){
44
+ shipping_address.addEventListener("focus", function( event ) {CURKLEAUTOCOMPLETE_SHIPPING.method.setAutocompleteCountry()}, true);
45
+ }
46
+
47
+ var shipping_country = document.getElementById("shipping:country_id");
48
+ if(shipping_country != null){
49
+ shipping_country.addEventListener("change", function( event ) {CURKLEAUTOCOMPLETE_SHIPPING.method.setAutocompleteCountry()}, true);
50
+ }
51
+
52
+
53
+ },
54
+ getIdSeparator : function() {
55
+ if (!document.getElementById('shipping:street1')) {
56
+ this.IdSeparator = "_";
57
+ return "_";
58
+ }
59
+ this.IdSeparator = ":";
60
+ return ":";
61
+ },
62
+ initFormFields: function ()
63
+ {
64
+ for (var field in this.formFields) {
65
+ this.formFields[field] = ('shipping' + this.IdSeparator + field);
66
+ }
67
+ this.component_form =
68
+ {
69
+ // 'administrative_area_level_3': ['street1', 'long_name'],
70
+ // 'neighborhood': ['street1', 'long_name'],
71
+ // 'subpremise': ['street1', 'short_name'],
72
+ 'street_number': ['street1', 'short_name'],
73
+ 'route': ['street1', 'long_name'],
74
+ // 'sublocality': ['street2', 'long_name'],
75
+ // 'sublocality_level_1': ['street2', 'long_name'],
76
+ 'locality': ['city', 'long_name'],
77
+ //'administrative_area_level_1': [formFields.region, 'long_name'],
78
+ 'administrative_area_level_1': ['region_id', 'long_name'],
79
+ 'postal_code': ['postcode', 'short_name']
80
+ };
81
+ },
82
+ // [START region_fillform]
83
+ fillInAddress : function () {
84
+ this.clearFormValues();
85
+ // Get the place details from the autocomplete object.
86
+ var place = this.autocomplete.getPlace();
87
+ this.resetForm();
88
+ var type = '';
89
+ for (var field in place.address_components) {
90
+ for (var t in place.address_components[field].types)
91
+ {
92
+ for (var f in this.component_form) {
93
+ var types = place.address_components[field].types;
94
+ if(f == types[t])
95
+ {
96
+ if(f == "street_number")
97
+ {
98
+ this.streetNumber = place.address_components[field]['short_name'];
99
+ }
100
+
101
+ var prop = this.component_form[f][1];
102
+ if(place.address_components[field].hasOwnProperty(prop)){
103
+ this.formFieldsValue[this.component_form[f][0]] = place.address_components[field][prop];
104
+ }
105
+
106
+ }
107
+ }
108
+ }
109
+ }
110
+
111
+ this.appendStreetNumber();
112
+ this.fillForm();
113
+ //for firecheckout only change zipcode
114
+ if(typeof FireCheckout !== 'undefined')
115
+ {
116
+ checkout.update(checkout.urls.shipping_address);
117
+ }
118
+ },
119
+
120
+ clearFormValues: function ()
121
+ {
122
+ for (var f in this.formFieldsValue) {
123
+ this.formFieldsValue[f] = '';
124
+ }
125
+ },
126
+ appendStreetNumber : function ()
127
+ {
128
+ if(this.streetNumber != '')
129
+ {
130
+ this.formFieldsValue['street1'] = this.streetNumber + ' '
131
+ + this.formFieldsValue['street1'];
132
+ }
133
+ },
134
+ fillForm : function()
135
+ {
136
+ for (var f in this.formFieldsValue) {
137
+ if(f == 'region_id' )
138
+ {
139
+ this.selectRegion( f,this.formFieldsValue[f]);
140
+ }
141
+ else
142
+ {
143
+ if(document.getElementById(('shipping' + this.IdSeparator + f)) === null){
144
+ continue;
145
+ }
146
+ else
147
+ {
148
+ document.getElementById(('shipping' + this.IdSeparator + f)).value = this.formFieldsValue[f];
149
+ }
150
+
151
+ }
152
+ }
153
+ },
154
+ selectRegion:function (id,regionText)
155
+ {
156
+ if(document.getElementById(('shipping' + this.IdSeparator + id)) == null){
157
+ return false;
158
+ }
159
+ var el = document.getElementById(('shipping' + this.IdSeparator + id));
160
+ for(var i=0; i<el.options.length; i++) {
161
+ if ( el.options[i].text == regionText ) {
162
+ el.selectedIndex = i;
163
+ break;
164
+ }
165
+ }
166
+ },
167
+ resetForm :function ()
168
+ {
169
+ if(document.getElementById(('shipping' + this.IdSeparator + 'street2')) !== null){
170
+ document.getElementById(('shipping' + this.IdSeparator + 'street2')).value = '';
171
+ }
172
+ },
173
+
174
+
175
+ setAutocompleteCountry : function () {
176
+
177
+ if(document.getElementById('shipping:country_id') === null){
178
+ country = 'US';//change your codes for default country
179
+ }
180
+ else
181
+ {
182
+ var country = document.getElementById('shipping:country_id').value;
183
+ }
184
+ this.autocomplete.setComponentRestrictions({ 'country': country });
185
+ }
186
+
187
+
188
+ }
189
+
190
+ window.addEventListener('load', function(){ CURKLEAUTOCOMPLETE_SHIPPING.method.initialize() });