Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Add ability to do city lookup matching from start of name only #54

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
5 changes: 4 additions & 1 deletion src/app/code/community/Fontis/Australia/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public function getPostcodeAutocompleteResults()
return array();
}

$cityQueryTet = (Mage::getStoreConfig("fontis_australia/postcode_autocomplete/match_start"))
? $this->getQueryText() : '%' . $this->getQueryText();

$res = Mage::getSingleton('core/resource');
/* @var $conn Varien_Db_Adapter_Pdo_Mysql */
$conn = $res->getConnection('australia_read');
Expand All @@ -120,7 +123,7 @@ public function getPostcodeAutocompleteResults()
INNER JOIN ' . $res->getTableName('directory_country_region') . ' AS dcr ON au.region_code = dcr.code
WHERE city LIKE :city ORDER BY city, region_code, postcode
LIMIT ' . $this->getPostcodeAutocompleteMaxResults(),
array('city' => '%' . $this->getQueryText() . '%')
array('city' => $cityQueryTet . '%')
);
}
}
9 changes: 9 additions & 0 deletions src/app/code/community/Fontis/Australia/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,15 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</max_results>
<match_start translate="label">
<label>Match 'Starts with'</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>15</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</match_start>
</fields>
</postcode_autocomplete>
<address_validation translate="label">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@
var citySuggestUrl = '<?php echo $this->helper('australia')->getCitySuggestUrl(); ?>';

//============ Billing ============//
var autocomplete_city_billing_indicator = new Element('div', {
id: 'autocomplete_city_billing_indicator',
'class': 'fontis-postcode-autocomplete-indicator',
'style': 'display:none;'
});
var autocomplete_city_billing = new Element('div', { id: 'autocomplete_city_billing', 'class': 'fontis-postcode-autocomplete' });

if ($('billing:city')) {
$('billing:city').parentNode.appendChild(autocomplete_city_billing);
if ($('billing:city')) {
$('billing:city').parentNode.appendChild(autocomplete_city_billing_indicator)
.parentNode.appendChild(autocomplete_city_billing);

function updateAddressBilling(text, item) {
// Update state and postcode fields
Expand All @@ -40,17 +46,24 @@
var completer = new Ajax.Autocompleter("billing:city", "autocomplete_city_billing", citySuggestUrl, {
afterUpdateElement: updateAddressBilling,
minChars: 2,
indicator: 'autocomplete_city_billing_indicator',
callback: function (inputElement, queryString) {
return queryString + '&' + 'country=' + $F('billing:country_id');
}
});
}

//============ Shipping ============//
var autocomplete_city_shipping_indicator = new Element('div', {
id: 'autocomplete_city_shipping_indicator',
'class': 'fontis-postcode-autocomplete-indicator',
'style': 'display:none;'
});
var autocomplete_city_shipping = new Element('div', { id: 'autocomplete_city_shipping', 'class': 'fontis-postcode-autocomplete' });

if ($('shipping:city')) {
$('shipping:city').parentNode.appendChild(autocomplete_city_shipping);
if ($('shipping:city')) {
$('shipping:city').parentNode.appendChild(autocomplete_city_shipping_indicator)
.parentNode.appendChild(autocomplete_city_shipping);

function updateAddressShipping(text, item) {
// Update state and postcode fields
Expand All @@ -66,6 +79,7 @@
var completer = new Ajax.Autocompleter("shipping:city", "autocomplete_city_shipping", citySuggestUrl, {
afterUpdateElement: updateAddressShipping,
minChars: 2,
indicator: 'autocomplete_city_shipping_indicator',
callback: function (inputElement, queryString) {
return queryString + '&' + 'country=' + $F('shipping:country_id');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@

// Create and insert the div that will hold the list of autocomplete items. This
// is added to the DOM immediately following the #city field.
var autocomplete_city_indicator = new Element('div', {
id: 'autocomplete_city_indicator',
'class': 'fontis-postcode-autocomplete-indicator',
'style': 'display:none;'
});
var autocomplete_city = new Element('div', { id: 'autocomplete_city', 'class': 'fontis-postcode-autocomplete' });
$('city').parentNode.appendChild(autocomplete_city);
$('city').parentNode.appendChild(autocomplete_city_indicator)
.parentNode.appendChild(autocomplete_city);

function updateAddress(text, item) {
// Update state and postcode fields
Expand All @@ -39,6 +45,7 @@
var completer = new Ajax.Autocompleter("city", "autocomplete_city", citySuggestUrl, {
afterUpdateElement: updateAddress,
minChars: 2,
indicator: 'autocomplete_city_indicator',
parameters: 'country=' + $F('country')
});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@
.fontis-postcode-autocomplete li.selected {
background-color:#f7e8dd;
}
.fontis-postcode-autocomplete-indicator {
background-image: url('../images/ajax-loader.gif');
height: 16px;
width: 16px;
float: right;
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.