please visit link
you can see there is an option to check delivery is available or not by entering zip code.
we saved list of zip codes in database table and if zip code is available in table, it show
"Delivery is avilable" otherwise it show " Not available".
example: 560043 is avialable. 5600431 is not available
I want to update this feature with following requirements.
for some zip codes, i want to display message as
1) Delivery is available, COD is available
for some other zip codes, i want to display message as
2) Delivery is available, COD is not available
Also for some,
3) Delivery is not available.
is this possible by saving zip codes in DB or is we have to save zip codes in files to get
this result ?
view.phtml
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('checkdelivery/checkdelivery.phtml')->toHtml();?>
checkdelivery.phtml
<div class="block-content" > <div id="block_info">
<img src ="" height= '35' width= '70'>
<?php $blockLabel = Mage::getStoreConfig('checkdelivery/general/block_title'); ?>
<strong><span><?php echo $this->__($blockLabel) ?></span></strong>
<input type="text" placeholder="Enter your PIN Code" class="input-text" maxlength="120" id="zipcode" size="20" name="zipcode" onkeypress="if (event.keyCode == 13) { return false;}">
<button type="button" name="zip-check" title="Check" class="button1" id="zip-check" ><span><?php echo $this->__('CHECK'); ?></span></button>
<div id="delivery-message"></div>
<?php $defaultHtml = Mage::getStoreConfig('checkdelivery/general/default_html'); ?>
<div id="delivery-html"><?php echo $defaultHtml ?></div>
</div>
</div>
<script>
document.getElementById('zipcode').onkeypress = function(e){
if (!e) e = window.event;
var keyCode = e.keyCode || e.which;
if (keyCode == '13'){
// Do your ajax process which you are doing on zip-check click button same way.
new Ajax.Request("<?php echo $this->getUrl('checkdelivery/index/index') ?>", {
method: "get",
parameters: {zipcode : $('zipcode').value },
onSuccess: function(transport) {
var json = transport.responseText.evalJSON();
$('delivery-message').update(json.message);
$('delivery-message').setStyle({ color: json.color});
$('delivery-html').update(json.html);
}
});
return false;
}
}
</script>
<script>
Event.observe('zip-check', 'click', function(event){
new Ajax.Request("<?php echo $this->getUrl('checkdelivery/index/index') ?>", {
method: "get",
parameters: {zipcode : $('zipcode').value },
onSuccess: function(transport) {
var json = transport.responseText.evalJSON();
$('delivery-message').update(json.message);
$('delivery-message').setStyle({ color: json.color});
$('delivery-html').update(json.html);
}
});
});
</script>
controllers/indexcontroller.php
public function indexAction() {
$zip = $this->getRequest()->getParam('zipcode');
$pincodearray = array();
$pindata = Mage::getStoreConfig('checkdelivery/general/pincode');
$pincodearray = explode(",", $pindata);
$success = Mage::getStoreConfig('checkdelivery/general/success_messgae');
$failure = Mage::getStoreConfig('checkdelivery/general/failure_messgae');
$empty = Mage::getStoreConfig('checkdelivery/general/empty_messgae');
$successHtml = Mage::getStoreConfig('checkdelivery/general/success_html');
$failureHtml = Mage::getStoreConfig('checkdelivery/general/failure_html');
$defaultHtml = Mage::getStoreConfig('checkdelivery/general/default_html');
$trimedZip = trim($zip);
$response = array();
if(isset($trimedZip) && !empty($trimedZip)){
if (in_array($trimedZip, $pincodearray)) {
$response['message'] = $success;
$response['color'] = 'green';
$response['html'] = $successHtml;
}else{
$response['message'] = $failure;
$response['color'] = 'red';
$response['html'] = $failureHtml;
}
}else{
$response['message'] = $empty;
$response['color'] = 'orange';
$response['html'] = $defaultHtml;
}
echo json_encode($response);exit;
}
checkdelivery/index/index
code too