I've recently started to create a shipping module for my opencart powered shop but I've run into a problem.
I need correct city names to calculate shipping rates and by default that is up to the user's input skills since there's no dropdown to select the city name in the address form.
I've already created a city database with these fields : (`city_id`, `zone_id`, `country_id`, `name`, `status`)
Now i've been trying to figure out how to implement that dropdown for the cities.
I think that for country and zone the magic happens in :
\catalog\view\theme\<theme_name>\template\account\address_form.tpl
I see there's an array used for countries named $countries that gets populated like this :
$this->load->model('localisation/country');
$this->data['countries'] = $this->model_localisation_country->getCountries();
in \catalog\controller\account\address.php
Then there's the little ajax part at the end of the \catalog\view\theme\<theme_name>\template\account\address_form.tpl that feeds the zone dropdown list :
Code: Select all
<script type="text/javascript"><!--
$('select[name=\'country_id\']').bind('change', function() {
$.ajax({
url: 'index.php?route=account/address/country&country_id=' + this.value,
dataType: 'json',
beforeSend: function() {
$('select[name=\'country_id\']').after('<span class="wait"> <img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('.wait').remove();
},
success: function(json) {
if (json['postcode_required'] == '1') {
$('#postcode-required').show();
} else {
$('#postcode-required').hide();
}
html = '<option value=""><?php echo $text_select; ?></option>';
if (json['zone'] != '') {
for (i = 0; i < json['zone'].length; i++) {
html += '<option value="' + json['zone'][i]['zone_id'] + '"';
if (json['zone'][i]['zone_id'] == '<?php echo $zone_id; ?>') {
html += ' selected="selected"';
}
html += '>' + json['zone'][i]['name'] + '</option>';
}
} else {
html += '<option value="0" selected="selected"><?php echo $text_none; ?></option>';
}
$('select[name=\'zone_id\']').html(html);
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
$('select[name=\'country_id\']').trigger('change');
//--></script>