UK_Postcode_Address_Finder - Version 1.6.0

Version Notes

Release History :
v 1.6.0
* added address lookup to the admin panel, to change order of address fields please see the
documentation tab - http://www.magentocommerce.com/boards/viewchild/17082/

v 1.5.1
* small modification following tests with the blank theme (changed order of initialisation in JavaScript)

v 1.5.0
* add config option for 1st result line.
* avoid using JavaScript DOM for modifying address forms - it was conflicting with Magento JavaScript.
We now edit the template .phtml files directly.
* fix problems with re-displaying state select box when country is changed from UK to USA.
* fix problem with postcode error message affecting button position if form was submitted with a blank postcode.

v 1.4.0
* make error message class configurable - it can now be styled to match other Magento errors
* make error message text configurable
* fix issue with error message not being shown if hiding of address fields was enabled

v 1.3.0
* populate the company field if company name is available
* unhide all address lines on lookup error to allow customer to enter the address manually
* update to latest CraftyClicks JavaScript (v3.5):
- added the on_error event
- fixed selection of result using keyboard (got broken in latest Firefox v3.5)

v 1.2.0
* can now hide the region/province (county) field
* update to latest CraftyClicks JavaScript (v3.4)

v 1.1.2 (bug fix release)
* fix typo in JS code

v 1.1.1 (bug fix release)
* fix rearranging address fields order; was causing problems on one page checkout
* fix hiding of result box on result select
* hide result box on country change

v 1.1.0
* added Admin Panel options to configure look and feel of the module
* add address lookup to multiship checkout pages

v 1.0.0 - Initial Release

Download this release

Release Info

Developer Magento Core Team
Extension UK_Postcode_Address_Finder
Version 1.6.0
Comparing to
See all releases


Code changes from version 1.5.1 to 1.6.0

app/code/local/Dnc/Craftyclicks/etc/config.xml CHANGED
@@ -12,7 +12,7 @@
12
<config>
13
<modules>
14
<Dnc_Craftyclicks>
15
- <version>1.5.1</version>
16
</Dnc_Craftyclicks>
17
</modules>
18
@@ -38,6 +38,7 @@
38
<general>
39
<craftyclicks>
40
<active>0</active>
41
<model>dnc/craftyclicks</model>
42
<access_token>xxxxx-xxxxx-xxxxx-xxxxx</access_token>
43
<button_image></button_image>
12
<config>
13
<modules>
14
<Dnc_Craftyclicks>
15
+ <version>1.6.0</version>
16
</Dnc_Craftyclicks>
17
</modules>
18
38
<general>
39
<craftyclicks>
40
<active>0</active>
41
+ <active_admin>0</active_admin>
42
<model>dnc/craftyclicks</model>
43
<access_token>xxxxx-xxxxx-xxxxx-xxxxx</access_token>
44
<button_image></button_image>
app/code/local/Dnc/Craftyclicks/etc/system.xml CHANGED
@@ -21,7 +21,7 @@
21
<show_in_store>0</show_in_store>
22
<fields>
23
<active translate="label">
24
- <label>Enabled</label>
25
<frontend_type>select</frontend_type>
26
<source_model>adminhtml/system_config_source_yesno</source_model>
27
<sort_order>1</sort_order>
@@ -30,6 +30,16 @@
30
<show_in_store>0</show_in_store>
31
</active>
32
33
<access_token translate="label">
34
<label>Access Token</label>
35
<frontend_type>text</frontend_type>
21
<show_in_store>0</show_in_store>
22
<fields>
23
<active translate="label">
24
+ <label>Enabled - Frontend</label>
25
<frontend_type>select</frontend_type>
26
<source_model>adminhtml/system_config_source_yesno</source_model>
27
<sort_order>1</sort_order>
30
<show_in_store>0</show_in_store>
31
</active>
32
33
+ <active_admin translate="label">
34
+ <label>Enabled - Admin Panel</label>
35
+ <frontend_type>select</frontend_type>
36
+ <source_model>adminhtml/system_config_source_yesno</source_model>
37
+ <sort_order>2</sort_order>
38
+ <show_in_default>1</show_in_default>
39
+ <show_in_website>1</show_in_website>
40
+ <show_in_store>0</show_in_store>
41
+ </active_admin>
42
+
43
<access_token translate="label">
44
<label>Access Token</label>
45
<frontend_type>text</frontend_type>
app/design/adminhtml/default/default/template/customer/tab/addresses.phtml ADDED
@@ -0,0 +1,587 @@
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@magentocommerce.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.magentocommerce.com for more information.
20
+ *
21
+ * @category design_default
22
+ * @package Mage
23
+ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <!-- Addresses list -->
28
+ <table cellspacing="0" class="form-edit">
29
+ <tr>
30
+ <td class="address-list">
31
+ <div class="entry-edit-head">
32
+ <h4 class="icon-head head-customer-address-list"><?php echo Mage::helper('customer')->__('Customer Addresses') ?></h4>
33
+ </div>
34
+ <div class="sub-btn-set"><?php echo $this->getAddNewButtonHtml() ?></div>
35
+ <ul id="address_list">
36
+ <?php $_iterator = 0; ?>
37
+ <?php if(count($addressCollection)): ?>
38
+ <?php foreach ($addressCollection as $_address): ?>
39
+ <li id="address_item_<?php echo $_address->getId() ?>">
40
+ <?php if (!$this->isReadonly()): ?>
41
+ <a href="#" class="btn-remove-address">
42
+ <img src="<?php echo $this->getSkinUrl('images/cancel_icon.gif') ?>" alt="Remove address" id="delete_button<?php echo ++$_iterator ?>" />
43
+ </a>
44
+ <a href="#" id="select_button_<?php echo $_address->getId() ?>" class="select_button btn-edit-address">
45
+ <img src="<?php echo $this->getSkinUrl('images/edit_icon.gif') ?>" alt="Edit address"/>
46
+ </a>
47
+ <?php endif;?>
48
+ <address>
49
+ <?php echo $_address->format('html') ?>
50
+ </address>
51
+ <div class="address-type">
52
+ <span class="address-type-line">
53
+ <input type="radio" <?php if ($this->isReadonly()):?> disabled="disabled"<?php endif;?> value="<?php echo $_address->getId() ?>" id="address_item_billing<?php echo $_address->getId() ?>" name="account[default_billing]" title="<?php echo Mage::helper('customer')->__('Set as Default Billing Address') ?>"<?php if($_address->getId()==$customer->getDefaultBilling()): ?> checked="checked"<?php endif; ?>/>
54
+ &nbsp;<label for="address_item_billing<?php echo $_address->getId() ?>"><?php echo Mage::helper('customer')->__('Default Billing Address') ?></label>
55
+ </span>
56
+ <span class="address-type-line">
57
+ <input type="radio" <?php if ($this->isReadonly()):?> disabled="disabled"<?php endif;?> value="<?php echo $_address->getId() ?>" id="address_item_shipping<?php echo $_address->getId() ?>" name="account[default_shipping]" title="<?php echo Mage::helper('customer')->__('Set as Default Shipping Address') ?>"<?php if($_address->getId()==$customer->getDefaultShipping()): ?> checked="checked"<?php endif; ?>/>
58
+ &nbsp;<label for="address_item_shipping<?php echo $_address->getId() ?>"><?php echo Mage::helper('customer')->__('Default Shipping Address') ?></label>
59
+ </span>
60
+ </div>
61
+ </li>
62
+ <?php endforeach; ?>
63
+ <?php endif; ?>
64
+ </ul>
65
+ </td>
66
+ <td>
67
+ <!-- Addresses forms -->
68
+ <div class="entry-edit" id="address_form_container">
69
+ <?php if(count($addressCollection)): ?>
70
+ <?php foreach ($addressCollection as $_address): ?>
71
+ <div id="form_address_item_<?php echo $_address->getId() ?>" style="display:none">
72
+ <?php
73
+ $this->getFormObject()->setValues($_address->getData())
74
+ ->setHtmlIdPrefix("id{$_address->getId()}")
75
+ ->setFieldNameSuffix('address['.$_address->getId().']')
76
+ ?>
77
+ <?php echo $this->getFormObject()->getHtml() ?>
78
+ <input type="hidden" name="address[<?php echo $_address->getId() ?>][_deleted]" id="deleted_address_item_<?php echo $_address->getId() ?>" />
79
+ </div>
80
+ <?php endforeach; ?>
81
+ <?php else: ?>
82
+ <div id="no_address_message"><?php echo Mage::helper('customer')->__('This customer has no saved addresses.') ?></div>
83
+ <?php endif; ?>
84
+ </div>
85
+
86
+ <!-- Template for adding address item to list -->
87
+ <?php $_templatePrefix = $this->getTemplatePrefix() ?>
88
+ <div id="address_item_template" class="no-display template">
89
+ <?php if (!$this->isReadonly()): ?>
90
+ <a href="#" class="btn-remove-address">
91
+ <img src="<?php echo $this->getSkinUrl('images/cancel_icon.gif') ?>" alt="Remove address" id="delete_button<?php echo ++$_iterator ?>" />
92
+ </a>
93
+ <a href="#" id="select_button_" class="select_button btn-edit-address">
94
+ <img src="<?php echo $this->getSkinUrl('images/edit_icon.gif') ?>" alt="Edit address"/>
95
+ </a>
96
+ <?php endif;?>
97
+ <address><?php echo Mage::helper('customer')->__('New Customer Address') ?></address>
98
+ <div class="address-type">
99
+ <span class="address-type-line">
100
+ <input <?php if ($this->isReadonly()):?> disabled="disabled"<?php endif;?> type="radio" value="<?php echo $_templatePrefix ?>" id="address_item_billing<?php echo $_templatePrefix ?>" name="account[default_billing]" title="<?php echo Mage::helper('customer')->__('Set as Default Billing Address') ?>"/>
101
+ &nbsp;<label for="address_item_billing<?php echo $_templatePrefix ?>"><?php echo Mage::helper('customer')->__('Default Billing Address') ?></label>
102
+ </span>
103
+ <span class="address-type-line">
104
+ <input <?php if ($this->isReadonly()):?> disabled="disabled"<?php endif;?> type="radio" value="<?php echo $_templatePrefix ?>" id="address_item_shipping<?php echo $_templatePrefix ?>" name="account[default_shipping]" title="<?php echo Mage::helper('customer')->__('Set as Default Shipping Address') ?>"/>
105
+ &nbsp;<label for="address_item_shipping<?php echo $_templatePrefix ?>"><?php echo Mage::helper('customer')->__('Default Shipping Address') ?></label>
106
+ </span>
107
+ </div>
108
+ </div>
109
+
110
+ <!-- Address form template -->
111
+ <div id="address_form_template" class="no-display template">
112
+ <?php
113
+ // Set form template elements prefix
114
+ $this->getFormObject()->setHtmlIdPrefix($_templatePrefix)
115
+ ->setValues(array())
116
+ ->setFieldNameSuffix('address['.$_templatePrefix.']');
117
+ ?>
118
+ <?php echo $this->getFormObject()->getHtml() ?>
119
+ <?php echo $this->getCancelButtonHtml() ?>
120
+ </div>
121
+
122
+
123
+ <?php // CraftyClicks - Start
124
+ $conf = Mage::getStoreConfig('general');
125
+ if ($conf['craftyclicks']['active_admin']) : ?>
126
+ <script type="text/javascript" charset="ISO-8859-1" src="<?php echo $this->getJsUrl('crafty/crafty_postcode.js'); ?>"></script>
127
+ <script type="text/javascript">
128
+ //<![CDATA[
129
+ var cp_obj = new Array();
130
+ //]]>
131
+ </script>
132
+ <?php endif // CraftyClicks - End ?>
133
+ <!-- -->
134
+ <script type="text/javascript">
135
+ //<![CDATA[
136
+ var deleteButtonId = <?php echo $_iterator ?>;
137
+
138
+ var addressesModel = Class.create();
139
+ addressesModel.prototype = {
140
+ initialize : function() {
141
+ this.activeItem = null;
142
+ this.itemTemplate = $('address_item_template');
143
+ this.formTemplate = $('address_form_template');
144
+ this.itemContainer= $('address_list');
145
+ this.formContainer= $('address_form_container');
146
+ this.baseItemId = 'new_item';
147
+
148
+ this.itemContentTemplate = new Template('<?php echo $this->helper('customer/address')->getFormat('js_template')?>');
149
+
150
+ this.onNewAddressClick = this.addNewAddress.bindAsEventListener(this);
151
+ this.onItemMouseOver = this.itemMouseOver.bindAsEventListener(this);
152
+ this.onItemMouseOut = this.itemMouseOut.bindAsEventListener(this);
153
+ this.onItemMouseClick = this.itemMouseClick.bindAsEventListener(this);
154
+ this.onItemFormFieldChange = this.syncFormData.bindAsEventListener(this);
155
+
156
+ this.loader = new varienLoader(true);
157
+ this.regionsUrl = '<?php echo $this->getRegionsUrl() ?>';
158
+
159
+ this.reloadItemList(1);
160
+
161
+ for(var i=0,n=this.itemList.length; i<n; i++){
162
+ if(this.itemList[i].id){
163
+ this.addItemObservers(this.itemList[i]);
164
+ this.initItem(this.itemList[i]);
165
+ }
166
+ }
167
+ if($('add_new_address_button')){
168
+ Event.observe('add_new_address_button', 'click', this.onNewAddressClick)
169
+ }
170
+
171
+ this.setActiveItem(this.itemList[0]);
172
+ this.setAddressAsDefault();
173
+ this.bindCountryRegionRelation();
174
+ },
175
+
176
+ reloadItemList : function(initial){
177
+ this.itemList = $('#address_list li');
178
+ if( initial ) {
179
+ this.itemCount = this.itemList.length;
180
+ }
181
+ if(!this.itemList.length){
182
+ if($('no_address_message')){
183
+ $('no_address_message').show();
184
+ }
185
+ else {
186
+ this.formContainer.innerHTML+= '<div id="no_address_message"><?php echo addslashes(Mage::helper('customer')->__('This customer has no saved addresses.')) ?></div>'
187
+ }
188
+ }
189
+ },
190
+
191
+ initItem : function(item){
192
+ if(item && $('form_'+item.id)){
193
+ item.formBlock = $('form_'+item.id);
194
+ Element.hide($('form_'+item.id));
195
+ $('form_'+item.id).statusBar = item;
196
+ $('form_'+item.id).addressItem = item;
197
+ }
198
+ },
199
+
200
+ addItemObservers : function(item){
201
+ if(item.id){
202
+ Event.observe(item, 'mouseover', this.onItemMouseOver);
203
+ Event.observe(item, 'mouseout', this.onItemMouseOut);
204
+ Event.observe(item, 'click', this.onItemMouseClick);
205
+ }
206
+ },
207
+
208
+ addNewAddress : function(event){
209
+ if(this.canCreateNewAddress){
210
+ this.itemCount++;
211
+ if($('no_address_message')){
212
+ $('no_address_message').hide();
213
+ }
214
+
215
+ // create new form elements
216
+ Element.insert(this.formContainer, {bottom:
217
+ '<div id="' + 'form_' + this.baseItemId + this.itemCount + '">'
218
+ + this.prepareTemplate(this.formTemplate.innerHTML)
219
+ + '</div>'
220
+ });
221
+
222
+ var newForm = $('form_' + this.baseItemId + this.itemCount);
223
+
224
+ $('_item'+this.itemCount+'firstname').value = $('_accountfirstname').value;
225
+ $('_item'+this.itemCount+'lastname').value = $('_accountlastname').value;
226
+
227
+ Element.hide(newForm);
228
+ var template = '<li id="' + this.baseItemId+this.itemCount + '">';
229
+ deleteButtonId ++;
230
+ template += this.prepareTemplate(this.itemTemplate.innerHTML).replace('delete_button', 'delete_button'+ deleteButtonId);
231
+ template += '</li>';
232
+ Element.insert(this.itemContainer, {bottom: template});
233
+ var newItem = $(this.baseItemId+this.itemCount);
234
+ newItem.isNewAddress = true;
235
+ newItem.formBlock = newForm;
236
+
237
+
238
+ newForm.statusBar = newItem;
239
+ newForm.addressItem = newItem;
240
+
241
+ this.addItemObservers(newItem);
242
+ this.setActiveItem(newItem);
243
+ this.bindCountryRegionRelation(newForm.id);
244
+
245
+ if( $('_item'+this.itemCount+'firstname').value ) this.syncFormData($('_item'+this.itemCount+'firstname'));
246
+ if( $('_item'+this.itemCount+'lastname').value ) this.syncFormData($('_item'+this.itemCount+'lastname'));
247
+ }
248
+ this.reloadItemList();
249
+ //Event.stop(event);
250
+ },
251
+
252
+ prepareTemplate : function(template){
253
+ return template
254
+ .replace(/<?php echo $_templatePrefix ?>/g, '_item'+this.itemCount)
255
+ .replace(/_counted="undefined"/g, '')
256
+ .replace(/"select_button_"/g, 'select_button_' + this.itemCount)
257
+ ;
258
+ },
259
+
260
+ canCreateNewAddress : function(){
261
+ return true;
262
+ },
263
+
264
+ itemMouseOver : function(event){
265
+ var element = Event.findElement(event, 'li');
266
+ Element.addClassName(element, 'over');
267
+ },
268
+
269
+ itemMouseOut : function(event){
270
+ var element = Event.findElement(event, 'li');
271
+ Element.removeClassName(element, 'over');
272
+ },
273
+
274
+ itemMouseClick : function(event){
275
+ if (!Event) {
276
+ return;
277
+ }
278
+ var element = Event.findElement(event, 'li'); // find top item
279
+ var elem = Event.element(event); // exact element clicked
280
+
281
+ if ( ((elem.tagName.toUpperCase() == 'A') && elem.id.match(/^delete_button([0-9]*?)#x2F;)) || ((elem.tagName.toUpperCase() == 'IMG') && elem.id.match(/^delete_button([0-9]*?)#x2F;)) ) {
282
+ this.deleteAddress(element);
283
+ Event.stop(event);
284
+ }
285
+ else if(elem.tagName.toUpperCase() == 'INPUT') {
286
+ this.setAddressAsDefault(element);
287
+ }
288
+ else {
289
+ this.setActiveItem(element);
290
+ }
291
+ },
292
+
293
+ setAddressAsDefault : function(){
294
+ for(var i=0; i<this.itemList.length;i++){
295
+ if(this.itemList[i].id){
296
+ var inputs = $(this.itemList[i].id).getElementsBySelector('input');
297
+ var isActive = false;
298
+ for(var j in inputs){
299
+ if(inputs[j].type=='radio' && inputs[j].checked && this.itemList.length > 1){
300
+ isActive = true;
301
+ }
302
+ }
303
+ this.toggleDeleteButton(this.itemList[i], !isActive);
304
+ }
305
+ }
306
+ },
307
+
308
+ toggleDeleteButton : function(item, flag){
309
+ if(flag){
310
+ $(item).select('.btn-remove-address').each(Element.show);
311
+ $(item.formBlock).getElementsBySelector('.delete-address').each(Element.show);
312
+ } else {
313
+ $(item).select('.btn-remove-address').each(Element.hide);
314
+ $(item.formBlock).getElementsBySelector('.delete-address').each(Element.hide);
315
+ }
316
+ },
317
+
318
+ setActiveItem : function(item){
319
+ if(this.activeItem){
320
+ Element.removeClassName(this.activeItem, 'on');
321
+ if($('form_'+this.activeItem.id)){
322
+ Element.hide($('form_'+this.activeItem.id));
323
+ }
324
+ }
325
+ Element.addClassName(item, 'on');
326
+
327
+ if(item && $('form_'+item.id)){
328
+ $('form_'+item.id).changeRelation = item;
329
+ $('form_'+item.id).addressItem = item;
330
+ Element.show($('form_'+item.id));
331
+ //new Effect.Appear($('form_'+item.id), {duration : 0.3 });
332
+ //$('form_'+item.id).focus();
333
+ this.addFieldChangeObserver($('form_'+item.id));
334
+ }
335
+
336
+ this.activeItem = item;
337
+ <?php // CraftyClicks - Start
338
+ if ($conf['craftyclicks']['active_admin']) : ?>
339
+ this.add_crafty_clicks(item);
340
+ <?php endif // CraftyClicks - End ?>
341
+ },
342
+
343
+ <?php // CraftyClicks - Start
344
+ if ($conf['craftyclicks']['active_admin']) :
345
+ $cp_access_token = $conf['craftyclicks']['access_token'];
346
+ ?>
347
+ ch_country : function(){
348
+ if (this.value!='GB')
349
+ $(this.alt+'findAddrBtn').style.display = 'none';
350
+ else
351
+ $(this.alt+'findAddrBtn').style.display = 'inline';
352
+ },
353
+
354
+ do_look : function(){
355
+ cp_obj[this.alt].doLookup();
356
+ },
357
+
358
+ add_crafty_clicks : function(item) {
359
+ // figure out the html elements id for this item
360
+ var item_html_id = '';
361
+ if (!item) {
362
+ return;
363
+ } else if ('address_item_' == item.id.substr(0,13)) {
364
+ item_html_id = 'id'+item.id.substr(13);
365
+ } else if ('new_item' == item.id.substr(0,8)) {
366
+ item_html_id = '_item'+item.id.substr(8);
367
+ }
368
+
369
+ if (!cp_obj[item_html_id]) {
370
+ // create a crafty clicks object
371
+ cp_obj[item_html_id] = CraftyPostcodeCreate();
372
+ cp_obj[item_html_id].set("max_width", '100%');
373
+ cp_obj[item_html_id].set("access_token", '<?php echo $cp_access_token; ?>');
374
+ cp_obj[item_html_id].set("result_elem_id", item_html_id+'crafty');
375
+ cp_obj[item_html_id].set("form", "");
376
+ cp_obj[item_html_id].set("elements", item_html_id+"company,"+item_html_id+"street0,"+item_html_id+"street1,,"+item_html_id+"city,"+item_html_id+"region,"+item_html_id+"postcode");
377
+ cp_obj[item_html_id].set("first_res_line", "----- please select your address ----");
378
+ cp_obj[item_html_id].set("res_autoselect", "0");
379
+ cp_obj[item_html_id].set("busy_img_url", "<?php echo $this->getJsUrl('crafty/crafty_postcode_busy.gif'); ?>");
380
+
381
+ // create the 'find address' button
382
+ var fndBtn;
383
+ fndBtn = document.createElement('input');
384
+ fndBtn.type='button';
385
+ fndBtn.alt = item_html_id;
386
+ fndBtn.id = item_html_id+'findAddrBtn';
387
+ fndBtn.value = '<?php echo $this->__('Find Address') ?>';
388
+ fndBtn.class = '<?php echo $conf['craftyclicks']['button_class']; ?>';
389
+
390
+ $(item_html_id+'postcode').style.width = '100px';
391
+ $(item_html_id+'postcode').parentNode.appendChild(fndBtn);
392
+ Event.observe(fndBtn.id, 'click', this.do_look);
393
+
394
+ var resTr = document.createElement('tr');
395
+ var resTd = document.createElement('td');
396
+ resTd.colSpan = '3';
397
+ resTd.id = item_html_id+'crafty'
398
+ resTr.appendChild(resTd);
399
+ var pcTr = $(item_html_id+'postcode').parentNode.parentNode;
400
+ pcTr.parentNode.insertBefore(resTr, pcTr.nextSibling);
401
+
402
+ $(item_html_id+'country_id').alt = item_html_id;
403
+ Event.observe(item_html_id+'country_id', 'change', this.ch_country);
404
+ }
405
+ // make button visible if country is UK
406
+ if ($(item_html_id+'country_id').value!='GB')
407
+ $(item_html_id+'findAddrBtn').style.display = 'none';
408
+ else
409
+ $(item_html_id+'findAddrBtn').style.display = 'inline';
410
+ },
411
+ <?php endif // CraftyClicks - End ?>
412
+
413
+ getFormContainerFields : function(container){
414
+ var fields = $( '#' + container.id + ' input','#' + container.id + ' select','#' + container.id + ' textarea');
415
+ return fields;
416
+ },
417
+
418
+ addFieldChangeObserver : function(container){
419
+ var fields = this.getFormContainerFields(container);
420
+ for (var i = 0; i < fields.length; i++) {
421
+ Event.observe(fields[i], 'change', this.onItemFormFieldChange);
422
+ }
423
+
424
+ },
425
+
426
+ syncFormData : function(evt){
427
+ var container = false;
428
+
429
+ if(!evt.addClassName) {
430
+ var elm = Event.element(evt);
431
+ } else {
432
+ var elm = evt;
433
+ }
434
+
435
+ elm = $(elm);
436
+ while(elm.tagName.toUpperCase() != 'BODY') {
437
+ if(elm.addressItem){
438
+ container = elm;
439
+ }
440
+ elm = $(elm.parentNode);
441
+ }
442
+
443
+ if(container){
444
+ var data = {};
445
+ var fields = this.getFormContainerFields(container);
446
+ for(var i=0; i < fields.size(); i++){
447
+ if(fields[i].id){
448
+ var id = fields[i].id.replace(/^(_item)?[0-9]+/, '');
449
+ var value = fields[i].getValue();
450
+ if(fields[i].tagName.toLowerCase()=='select'){
451
+ data[id] = fields[i].options[fields[i].selectedIndex].text.escapeHTML();
452
+ }
453
+ else{
454
+ data[id] = value.escapeHTML();
455
+ }
456
+ }
457
+ }
458
+ var itemContainer = container.addressItem.getElementsBySelector('address');
459
+ if(itemContainer[0]){
460
+
461
+ var html = this.itemContentTemplate.evaluate(data);
462
+ html = html.replace(new RegExp('(<br\\s*/?>\\s*){2,}','img'),'<br/>');
463
+ html = html.replace(new RegExp('<br\\s*/?>(\\s*,){1,}\\s*<br\\s*/?>','ig'),'<br/>');
464
+ html = html.replace(new RegExp('t:\\s*<br\\s*/?>','ig'),'');
465
+ html = html.replace(new RegExp('f:\\s*#x27;,'ig'),'');
466
+ itemContainer[0].innerHTML = html;
467
+ }
468
+ }
469
+ },
470
+
471
+ deleteAddress : function(item){
472
+ if(confirm('<?php echo Mage::helper('customer')->__('Are you sure you want to delete this address?') ?>')){
473
+ if( item.isNewAddress){
474
+ if ( this.activeItem == item ) this.formContainer.removeChild(item.formBlock);
475
+ } else {
476
+ if($('deleted_'+item.id)){
477
+ $('deleted_'+item.id).value = 1;
478
+ if(item.formBlock){
479
+ item.formBlock.addClassName('ignore-validation');
480
+ }
481
+ }
482
+ }
483
+
484
+ if ( this.activeItem == item && item != this.itemList[0] ) this.setActiveItem(this.itemList[0]);
485
+ if ( item == this.itemList[0] && (this.itemList[1]) ) this.setActiveItem(this.itemList[1]);
486
+
487
+ this.itemContainer.removeChild(item);
488
+ this.reloadItemList();
489
+ this.setAddressAsDefault();
490
+ }
491
+ },
492
+
493
+ cancelAdd : function(button){
494
+ if(confirm('<?php echo addslashes(Mage::helper('customer')->__('Are you sure you want to cancel adding of this address?')) ?>')){
495
+ var item = $(this.baseItemId + button.id.replace(new RegExp('[a-z_]*',''), ''));
496
+
497
+ if( item.isNewAddress){
498
+ if ( this.activeItem == item ) this.formContainer.removeChild(item.formBlock);
499
+ }
500
+ if ( this.activeItem == item && item != this.itemList[0] ) this.setActiveItem(this.itemList[0]);
501
+ if ( item == this.itemList[0] && (this.itemList[1]) ) this.setActiveItem(this.itemList[1]);
502
+
503
+ this.itemContainer.removeChild(item);
504
+
505
+ this.reloadItemList();
506
+ this.setAddressAsDefault();
507
+ }
508
+ },
509
+
510
+ bindCountryRegionRelation : function(parentId){
511
+ //alert('OK');
512
+ var countryElements = $('.countries');
513
+ for(var i=0;i<=countryElements.length;i++){
514
+ if(countryElements[i]){
515
+ if(!countryElements[i].bindRegions || !countryElements[i].parentBindId || countryElements[i].parentBindId!=parentId){
516
+ //if(!countryElements[i].bindRegions || !countryElements[i].parentBindId){
517
+ Event.observe(countryElements[i], 'change', this.reloadRegionField.bind(this));
518
+
519
+ countryElements[i].bindRegions = true;
520
+ countryElements[i].parentBindId = parentId;
521
+ }
522
+ }
523
+ }
524
+ },
525
+
526
+ reloadRegionField : function(event){
527
+ var countryElement = Event.element(event);
528
+ if(countryElement.id){
529
+ var regionElement = $(countryElement.id.replace(/country_id/, 'region'));
530
+ if(regionElement){
531
+ this.regionElement = regionElement;
532
+ var url = this.regionsUrl+'parent/'+countryElement.value;
533
+ this.loader.load(url, {}, this.refreshRegionField.bind(this));
534
+ }
535
+ }
536
+ },
537
+
538
+ refreshRegionField : function(serverResponse){
539
+ if(serverResponse){
540
+ var data = eval('(' + serverResponse + ')');
541
+ var value = this.regionElement.value;
542
+
543
+ var row = Element.previous(this.regionElement.parentNode,0);
544
+ var reqLabel = Element.select(row, '.required');
545
+ if (data.length) {
546
+ var html = '<select name="'+this.regionElement.name+'" id="'+this.regionElement.id+'" class="required-entry select" title="'+this.regionElement.title+'">';
547
+ html+= '<option value=""></option>';
548
+ for (var i in data){
549
+ if(data[i].label) {
550
+ html+= '<option value="'+data[i].value+'"';
551
+ if(this.regionElement.value && (this.regionElement.value == data[i].value || this.regionElement.value == data[i].label)){
552
+ html+= ' selected="selected"';
553
+ }
554
+ html+='>'+data[i].label+'</option>';
555
+ }
556
+ }
557
+ html+= '</select>';
558
+ if(reqLabel){
559
+ reqLabel.each(function(item){Element.show(item)});
560
+ }
561
+
562
+ var parentNode = this.regionElement.parentNode;
563
+ var regionElementId = this.regionElement.id;
564
+ parentNode.innerHTML = html;
565
+ this.regionElement = $(regionElementId);
566
+
567
+ //new Insertion.Before(this.regionElement, html);
568
+ //Element.remove(this.regionElement);
569
+ }
570
+ else{
571
+ var html = '<input type="text" name="'+this.regionElement.name+'" id="'+this.regionElement.id+'" class="input-text" title="'+this.regionElement.title+'">';
572
+ if(reqLabel){
573
+ reqLabel.each(function(item){Element.hide(item)});
574
+ }
575
+ Element.insert(this.regionElement, {before: html});
576
+ Element.remove(this.regionElement);
577
+ }
578
+ }
579
+ }
580
+ }
581
+
582
+ customerAddresses = new addressesModel();
583
+ //]]>
584
+ </script>
585
+ </td>
586
+ </tr>
587
+ </table>
app/design/adminhtml/default/default/template/sales/order/create/form/address.phtml ADDED
@@ -0,0 +1,148 @@
1
+ <?php if($this->getIsShipping()):
2
+ $_fieldsContainerId = 'order-shipping_address_fields';
3
+ ?>
4
+ <script type="text/javascript">
5
+ order.shippingAddressContainer = '<?php echo $_fieldsContainerId ?>';
6
+ order.setAddresses(<?php echo $this->getAddressCollectionJson() ?>);
7
+ </script>
8
+ <?php
9
+ else:
10
+ $_fieldsContainerId = 'order-billing_address_fields';
11
+ ?>
12
+ <script type="text/javascript">
13
+ order.billingAddressContainer = '<?php echo $_fieldsContainerId ?>';
14
+ </script>
15
+ <?php
16
+ endif; ?>
17
+ <div class="entry-edit">
18
+ <div class="entry-edit-head">
19
+ <h4 class="icon-head fieldset-legend <?php echo $this->getHeaderCssClass() ?>"><?php echo $this->getHeaderText() ?></h4>
20
+ </div>
21
+
22
+ <fieldset class="np">
23
+ <div class="order-choose-address">
24
+ <?php echo Mage::helper('sales')->__('Select from existing customer addresses:') ?><br />
25
+ <?php $_id = $this->getForm()->getHtmlIdPrefix() . 'customer_address_id' ?>
26
+ <select id="<?php echo $_id ?>" name="<?php echo $this->getForm()->getHtmlNamePrefix()?>[customer_address_id]" style="width:97.5%;" onchange="order.selectAddress(this, '<?php echo $_fieldsContainerId ?>')">
27
+ <option value=""><?php echo Mage::helper('sales')->__('Add New Address') ?></option>
28
+ <?php foreach ($this->getAddressCollection() as $_address): ?>
29
+ <?php //if($this->getAddressAsString($_address)!=$this->getAddressAsString($this->getAddress())): ?>
30
+ <option value="<?php echo $_address->getId() ?>"<?php if ($_address->getId()==$this->getAddressId()): ?> selected="selected"<?php endif; ?>>
31
+ <?php echo $this->getAddressAsString($_address) ?>
32
+ </option>
33
+ <?php //endif; ?>
34
+ <?php endforeach; ?>
35
+
36
+ </select>
37
+ <br />
38
+ <?php if($this->getIsShipping()): ?>
39
+ <input type="checkbox" id="order-shipping_same_as_billing" name="shipping_same_as_billing" onchange="order.setShippingAsBilling(this.checked)" <?php if($this->getIsAsBilling()): ?>checked<?php endif; ?>/>
40
+ <label for="order-shipping_same_as_billing" class="no-float"><?php echo Mage::helper('sales')->__('Same As Billing Address') ?></label>
41
+ <?php else: ?>
42
+ &nbsp;
43
+ <?php endif; ?>
44
+ </div>
45
+
46
+ <div class="order-address" id="<?php echo $_fieldsContainerId ?>">
47
+ <div class="content">
48
+ <?php echo $this->getForm()->toHtml() ?>
49
+ </div>
50
+ <div class="order-save-in-address-book">
51
+ <input name="<?php echo $this->getForm()->getHtmlNamePrefix()?>[save_in_address_book]" type="checkbox" id="<?php echo $this->getForm()->getHtmlIdPrefix()?>save_in_address_book" value="1" <?php if ($this->getAddress()->getSaveInAddressBook()):?> checked="checked"<?php endif;?>/>
52
+ <label for="<?php echo $this->getForm()->getHtmlIdPrefix()?>save_in_address_book"><?php echo Mage::helper('sales')->__('Save in address book') ?></label>
53
+ </div>
54
+ </div>
55
+ <?php $hideElement = 'address-' . ($this->getIsShipping() ? 'shipping' : 'billing') . '-overlay'; ?>
56
+ <div style="display:none;" id="<?php echo $hideElement ?>" class="overlay"><span><?php echo $this->__('Shipping address selection is not applicable') ?></span></div>
57
+ <script type="text/javascript">
58
+ order.bindAddressFields('<?php echo $_fieldsContainerId ?>')
59
+ <?php if($this->getIsShipping() && $this->getIsAsBilling()): ?>
60
+ order.disableShippingAddress(true);
61
+ <?php endif; ?>
62
+ </script>
63
+ </fieldset>
64
+ </div>
65
+ <?php // CraftyClicks - Start
66
+ $conf = Mage::getStoreConfig('general');
67
+ if ($conf['craftyclicks']['active_admin']) :
68
+ if( ! $this->getIsShipping()) :
69
+ $cp_access_token = $conf['craftyclicks']['access_token'];
70
+ ?>
71
+ <script type="text/javascript" charset="ISO-8859-1" src="<?php echo $this->getJsUrl('crafty/crafty_postcode.js'); ?>"></script>
72
+ <script type="text/javascript">
73
+ //<![CDATA[
74
+ var cp_obj = new Array();
75
+ function ch_country () {
76
+ if (this.value!='GB')
77
+ $(this.alt+'findAddrBtn').style.display = 'none';
78
+ else
79
+ $(this.alt+'findAddrBtn').style.display = 'inline';
80
+ }
81
+
82
+ function do_look() {
83
+ cp_obj[this.alt].doLookup();
84
+ }
85
+
86
+ function add_crafty_clicks(item_html_id) {
87
+ if (!cp_obj[item_html_id]) {
88
+ // create a crafty clicks object
89
+ cp_obj[item_html_id] = CraftyPostcodeCreate();
90
+ cp_obj[item_html_id].set("max_width", '100%');
91
+ cp_obj[item_html_id].set("access_token", '<?php echo $cp_access_token; ?>');
92
+ cp_obj[item_html_id].set("result_elem_id", item_html_id+'crafty');
93
+ cp_obj[item_html_id].set("form", "");
94
+ cp_obj[item_html_id].set("elements", item_html_id+"company,"+item_html_id+"street0,"+item_html_id+"street1,,"+item_html_id+"city,"+item_html_id+"region,"+item_html_id+"postcode");
95
+ cp_obj[item_html_id].set("first_res_line", "----- please select your address ----");
96
+ cp_obj[item_html_id].set("res_autoselect", "0");
97
+ cp_obj[item_html_id].set("busy_img_url", "<?php echo $this->getJsUrl('crafty/crafty_postcode_busy.gif'); ?>");
98
+
99
+ // create the 'find address' button
100
+ var fndBtn;
101
+ fndBtn = document.createElement('input');
102
+ fndBtn.type='button';
103
+ fndBtn.alt = item_html_id;
104
+ fndBtn.id = item_html_id+'findAddrBtn';
105
+ fndBtn.value='<?php echo $this->__('Find Address') ?>';
106
+ fndBtn.style.display='none';
107
+ fndBtn.style.fontSize='10px';
108
+ fndBtn.style.width='70px';
109
+
110
+ // $(item_html_id+'postcode').style.width = '100px';
111
+ $(item_html_id+'postcode').setAttribute('style', 'width:100px !important');
112
+
113
+ $(item_html_id+'postcode').parentNode.appendChild(fndBtn);
114
+ Event.observe(fndBtn.id, 'click', do_look);
115
+
116
+ var resTr = document.createElement('tr');
117
+ var resTd = document.createElement('td');
118
+ resTd.colSpan = '3';
119
+ resTd.id = item_html_id+'crafty'
120
+ resTr.appendChild(resTd);
121
+ var pcTr = $(item_html_id+'postcode').parentNode.parentNode;
122
+ pcTr.parentNode.insertBefore(resTr, pcTr.nextSibling);
123
+
124
+ $(item_html_id+'country_id').alt = item_html_id;
125
+ Event.observe(item_html_id+'country_id', 'change', ch_country);
126
+ }
127
+ // make button visible if country is UK
128
+ if ($(item_html_id+'country_id').value!='GB')
129
+ $(item_html_id+'findAddrBtn').style.display = 'none';
130
+ else
131
+ $(item_html_id+'findAddrBtn').style.display = 'inline';
132
+ }
133
+ add_crafty_clicks('order-billing_address_');
134
+ //]]>
135
+ </script>
136
+ <?php
137
+ endif; // if( ! $this->getIsShipping()) :
138
+
139
+ if($this->getIsShipping()): ?>
140
+
141
+ <script type="text/javascript">
142
+ //<![CDATA[
143
+ add_crafty_clicks('order-shipping_address_')
144
+ //]]>
145
+ </script>
146
+ <?php
147
+ endif; // if($this->getIsShipping()):
148
+ endif; // CraftyClicks - End ?>
app/etc/modules/Dnc_Craftyclicks.xml CHANGED
@@ -4,7 +4,7 @@
4
<Dnc_Craftyclicks>
5
<active>true</active>
6
<codePool>local</codePool>
7
- <version>1.5.1</version>
8
</Dnc_Craftyclicks>
9
</modules>
10
</config>
4
<Dnc_Craftyclicks>
5
<active>true</active>
6
<codePool>local</codePool>
7
+ <version>1.6.0</version>
8
</Dnc_Craftyclicks>
9
</modules>
10
</config>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
<?xml version="1.0"?>
2
<package>
3
<name>UK_Postcode_Address_Finder</name>
4
- <version>1.5.1</version>
5
<stability>stable</stability>
6
<license uri="http://www.opensource.org/licenses/osl-3.0.php">Open Software License ("OSL") v. 3.0</license>
7
<channel>community</channel>
@@ -17,6 +17,10 @@ Please note:
17
18
2. The extension is free to try and install, but to go live a paid up account with CraftyClicks.co.uk will be required. For current prices please go to http://www.craftyclicks.co.uk/prices</description>
19
<notes>Release History :
20
v 1.5.1
21
* small modification following tests with the blank theme (changed order of initialisation in JavaScript)
22
@@ -57,9 +61,9 @@ v 1.1.0
57
58
v 1.0.0 - Initial Release</notes>
59
<authors><author><name>Adam Stylo</name><user>auto-converted</user><email>adam@craftyclicks.co.uk</email></author></authors>
60
- <date>2009-12-16</date>
61
- <time>16:51:45</time>
62
- <contents><target name="mage"><dir name="app"><dir name="design"><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="craftyclicks.xml" hash="3167430f327a75925cb13d037b517e8f"/></dir><dir name="template"><dir name="dnc"><dir name="craftyclicks"><file name="address_form.phtml" hash="fcb3cc2696ac5b98c9ba7a2e87d908ae"/><file name="checkout_onepage.phtml" hash="a083c7d757e759520543e1d13e86191c"/><file name="crafty_template_helper.php" hash="5281028c45f0ddbc11582e8cc384a07a"/><dir name="checkout"><dir name="onepage"><file name="billing.phtml" hash="f51ac769fb1e90cd4ea6e8bba3ac819d"/><file name="shipping.phtml" hash="69a42e999e1ccd5ebebd4b12ad9720d7"/></dir></dir><dir name="customer"><dir name="address"><file name="edit.phtml" hash="3742dd587b877780b7229e81704a9232"/></dir></dir></dir></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Dnc_Craftyclicks.xml" hash="ffd98c66215b57be463342c773ef1dc3"/></dir></dir></dir></target><target name="magelocal"><dir name="Dnc"><dir name="Craftyclicks"><dir name="etc"><file name="config.xml" hash="1615a917d5d663039defbcee69e29a03"/><file name="system.xml" hash="52c6a51d533deb0e296344ff93ed23eb"/></dir><dir name="Helper"><file name="Data.php" hash="10c8592d3f990953767d6c96c2d0d5f4"/></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="default"><dir name="default"><dir name="craftyclicks"><file name="button_find_address.gif" hash="0fdef9bf7ad0f7ec3f6530b7ff40bf59"/><file name="crafty_postcode_busy.gif" hash="618a14f4dca4f51100cd2400e7f9049c"/></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="crafty"><file name="crafty_postcode.js" hash="fd0d40350eeb89c43dbd40c73c3f324f"/></dir></dir></target></contents>
63
<compatible/>
64
<dependencies/>
65
</package>
1
<?xml version="1.0"?>
2
<package>
3
<name>UK_Postcode_Address_Finder</name>
4
+ <version>1.6.0</version>
5
<stability>stable</stability>
6
<license uri="http://www.opensource.org/licenses/osl-3.0.php">Open Software License ("OSL") v. 3.0</license>
7
<channel>community</channel>
17
18
2. The extension is free to try and install, but to go live a paid up account with CraftyClicks.co.uk will be required. For current prices please go to http://www.craftyclicks.co.uk/prices</description>
19
<notes>Release History :
20
+ v 1.6.0
21
+ * added address lookup to the admin panel, to change order of address fields please see the
22
+ documentation tab - http://www.magentocommerce.com/boards/viewchild/17082/
23
+
24
v 1.5.1
25
* small modification following tests with the blank theme (changed order of initialisation in JavaScript)
26
61
62
v 1.0.0 - Initial Release</notes>
63
<authors><author><name>Adam Stylo</name><user>auto-converted</user><email>adam@craftyclicks.co.uk</email></author></authors>
64
+ <date>2009-12-18</date>
65
+ <time>13:46:41</time>
66
+ <contents><target name="mage"><dir name="app"><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="customer"><dir name="tab"><file name="addresses.phtml" hash="97f750943197afcbee9d198d09e20a42"/></dir></dir><dir name="sales"><dir name="order"><dir name="create"><dir name="form"><file name="address.phtml" hash="eb9eecd1764e7c3ee575e6fed3e7ca40"/></dir></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="craftyclicks.xml" hash="3167430f327a75925cb13d037b517e8f"/></dir><dir name="template"><dir name="dnc"><dir name="craftyclicks"><file name="address_form.phtml" hash="fcb3cc2696ac5b98c9ba7a2e87d908ae"/><file name="checkout_onepage.phtml" hash="a083c7d757e759520543e1d13e86191c"/><file name="crafty_template_helper.php" hash="5281028c45f0ddbc11582e8cc384a07a"/><dir name="checkout"><dir name="onepage"><file name="billing.phtml" hash="f51ac769fb1e90cd4ea6e8bba3ac819d"/><file name="shipping.phtml" hash="69a42e999e1ccd5ebebd4b12ad9720d7"/></dir></dir><dir name="customer"><dir name="address"><file name="edit.phtml" hash="3742dd587b877780b7229e81704a9232"/></dir></dir></dir></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Dnc_Craftyclicks.xml" hash="385ffb6ed9f9553b03a0246c32c28fef"/></dir></dir></dir></target><target name="magelocal"><dir name="Dnc"><dir name="Craftyclicks"><dir name="etc"><file name="config.xml" hash="16ffff0eb6600c3aad7080b2037b941b"/><file name="system.xml" hash="a1e2d68feaf1b3c0fb259208a85fd262"/></dir><dir name="Helper"><file name="Data.php" hash="10c8592d3f990953767d6c96c2d0d5f4"/></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="default"><dir name="default"><dir name="craftyclicks"><file name="button_find_address.gif" hash="0fdef9bf7ad0f7ec3f6530b7ff40bf59"/><file name="crafty_postcode_busy.gif" hash="618a14f4dca4f51100cd2400e7f9049c"/></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="crafty"><file name="crafty_postcode.js" hash="fd0d40350eeb89c43dbd40c73c3f324f"/></dir></dir></target></contents>
67
<compatible/>
68
<dependencies/>
69
</package>