I am testing opencart in XAMPP. I added this extension which checks zip code and enables to give zip code based shipping. Demo is here. It may not be compatible with the latest version.
The code was not working initially and after some modifications the admin side works. I can insert/modify zip code, etc., which means there is no issues in database.
In the catalog side however I am helpless. There is this ajax button which is not working.
<div class="pincode">
<span><strong>Enter pincode to check serviceability:</strong></span><br><br>
<input type="text" name="zip_code" value="" id="zip_code" size="8">
<a id="button_zipcode" class="button" title="Check"><span>Check</span></a><br><br>
<div id="temp_zipcode" style="width:94%;"></div>
which gets enabled with this script
$('#button_zipcode').bind('click', function() {
$.ajax({
url: 'index.php?route=product/product/zipcode',
type: 'post',
data: 'zip_code='+$('#zip_code').val(),
dataType: 'json',
success: function(json) {
$('.success, .warning, .attention, information, .error').remove();
if (json['warning']) {
$('#temp_zipcode').html('<div class="warning" style="display: none;">' + json['warning'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
$('.warning').fadeIn('slow');
}
if (json['success']) {
$('#temp_zipcode').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
$('.success').fadeIn('slow');
}
}
});
});
url: 'index.php?route=product/product/zipcode',
what this means? if it is controller/product/product.php what should I add to make it work? The code should check zip code with DB and give output.
And there is another page as catalog/model/localisation/zip_code.php which has
<?php
class ModelLocalisationZipCode extends Model {
public function getZipCode($zip_code_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zip_code WHERE zip_code_id = '" . (int)$zip_code_id . "' AND status = '1'");
return $query->row;
}
public function getCodeByZip($zip_code) {
$query1 = $this->db->query("SELECT * FROM " . DB_PREFIX . "zip_code WHERE zip_code LIKE '" . $zip_code . "' AND status = '1'");
return $query1;
}
}
?>
Is there anyway to make it work? Thanks in advance...
In your catalog/controller/product/product.php
add the fallowing code :
public function zipcode() {
$this->language->load('product/zipcode');
$this->load->model('localisation/zip_code');
$json = array();
if (isset($this->request->post['zip_code'])) {
$zip_code = $this->request->post['zip_code'];
} else {
$zip_code = 0;
}
$zone_data = $this->model_localisation_zip_code->getCodeByZip($zip_code);
if($zone_data->num_rows == 0)
{
$json['warning'] = sprintf($this->language->get('text_warning'));
}
else
{
$city_name = $zone_data->row['city_name'];
$state_name = $zone_data->row['state_name'];
$zone_name = $zone_data->row['zone_name'];
$json['success'] = sprintf($this->language->get('text_success'), $city_name, $state_name, $zone_name);
}
$this->response->setOutput(json_encode($json));
}