we are using custom module for displaying shipping charges in Product View page. you can download using Magento Display shipping estimation block
its working fine for in stock products, but its not working for out of stock products :
form.phtml
<?php if ($this->isEnabled()): ?>
<div class="block block-shipping-estimate" id="unique_id">
<img src ="http://totaltoys.com/media/font-100.png" height="35" width="70" class ="ikon">
<div class="block-title">
<strong><span><?php echo Mage::helper('webdevlopers_productpageshipping')->getTitle(); ?></span></strong>
</div>
<div class="block-content">
<p class="block-subtitle">
<?php echo Mage::helper('webdevlopers_productpageshipping')->getDes(); ?>
</p>
<ul class="shipping-estimation-form" id="shipping-estimation-form">
<?php if ($this->isFieldVisible('country')): ?>
<li class="item">
<label for="estimate_country" class="required"><em>*</em><?php echo Mage::helper('webdevlopers_productpageshipping')->__('Country') ?></label>
<div class="input-box">
<?php echo Mage::getBlockSingleton('directory/data')->getCountryHtmlSelect(
($this->getFieldValue('country') ? $this->getFieldValue('country') : $this->getConfig()->getDefaultCountry()),
'estimate[country_id]',
'estimate_country'
);
?>
</div>
</li>
<?php else: ?>
<input type="hidden" id="estimate_country" name="estimate[country_id]" value="<?php echo $this->htmlEscape($this->getConfig()->getDefaultCountry())?>" />
<?php endif; ?>
<?php if ($this->isFieldVisible('region')): ?>
<li class="item">
<label for="estimate_region_id"<?php if ($this->isFieldRequired('region')):?> class="required" <?php endif;?>><?php if ($this->isFieldRequired('region')):?><em>*</em><?php endif;?><?php echo $this->__('State/Province') ?></label>
<div class="input-box">
<select id="estimate_region_id" name="estimate[region_id]" title="<?php echo Mage::helper('webdevlopers_productpageshipping')->__('State/Province') ?>" style="display:none;"<?php echo ($this->isFieldRequired('region') ? ' class="validate-select"' : '') ?>>
<option value=""><?php echo Mage::helper('webdevlopers_productpageshipping')->__('Please select an option') ?></option>
</select>
<script type="text/javascript">
//<![CDATA[
$('estimate_region_id').setAttribute('defaultValue', '<?php echo $this->jsQuoteEscape($this->getFieldValue('region_id')); ?>');
//]]>
</script>
<input type="text" id="estimate_region" name="estimate[region]" value="<?php echo $this->htmlEscape($this->getFieldValue('region')) ?>" title="<?php echo Mage::helper('webdevlopers_productpageshipping')->__('State/Province') ?>" class="input-text" style="display:none;" />
</div>
</li>
<script type="text/javascript">
//<![CDATA[
new RegionUpdater('estimate_country', 'estimate_region', 'estimate_region_id', <?php echo $this->helper('directory')->getRegionJson() ?>);
//]]>
</script>
<?php endif; ?>
<?php if($this->isFieldVisible('city')): ?>
<li class="item">
<label for="city"<?php if ($this->isFieldRequired('city')):?> class="required" <?php endif;?>><?php if ($this->isFieldRequired('city')):?><em>*</em><?php endif;?><?php echo Mage::helper('webdevlopers_productpageshipping')->__('City') ?></label>
<div class="input-box">
<input class="input-text<?php if ($this->isFieldRequired('city')):?> required-entry<?php endif;?>" id="estimate_city" type="text" name="estimate[city]" value="<?php echo $this->htmlEscape($this->getFieldValue('city')) ?>" />
</div>
</li>
<?php endif; ?>
<?php if ($this->isFieldVisible('postcode')): ?>
<li class="item">
<label for="search"<?php if ($this->isFieldRequired('postcode')):?> class="required" <?php endif;?>><?php if ($this->isFieldRequired('postcode')):?><em>*</em><?php endif;?><?php echo Mage::helper('webdevlopers_productpageshipping')->__('') ?></label>
<div class="search">
<input placeholder="Enter your PIN Code" class="input-text <?php if ($this->isFieldRequired('postcode')):?>
required-entry<?php endif;?> validate-length maximum-length-6 minimum-length-6 validate-digits"
type="text" id="estimate_postcode" name="estimate[postcode]"
value="<?php echo $this->htmlEscape($this->getFieldValue('postcode')) ?>"
onkeydown="if (event.keyCode == 13) { return false;}" />
</div>
</li>
<?php endif; ?>
<?php if ($this->isFieldVisible('coupon_code')): ?>
<li class="item">
<label for="estimate_coupon_code"<?php if ($this->isFieldRequired('coupon_code')):?> class="required" <?php endif;?>><?php if ($this->isFieldRequired('coupon_code')):?><em>*</em><?php endif;?><?php echo Mage::helper('webdevlopers_productpageshipping')->__('Coupon Code') ?></label>
<div class="input-box">
<input class="input-text <?php if ($this->isFieldRequired('coupon_code')):?> required-entry<?php endif;?>" type="text" id="estimate_coupon_code" name="estimate[coupon_code]" value="<?php echo $this->htmlEscape($this->getFieldValue('coupon_code')) ?>" />
</div>
</li>
<?php endif; ?>
<?php if ($this->isFieldVisible('cart')): ?>
<li class="item radio">
<label for="estimate_cart_yes"><?php echo Mage::helper('webdevlopers_productpageshipping')->__('Include Cart Items') ?></label>
<div class="input-box">
<input type="radio" id="estimate_cart_yes" name="estimate[cart]" value="1" <?php if ($this->useShoppingCart()): ?> checked="checked"<?php endif;?> /><?php echo Mage::helper('webdevlopers_productpageshipping')->__('Yes') ?>
<input type="radio" id="estimate_cart_no" name="estimate[cart]" value="0" <?php if (!$this->useShoppingCart()): ?> checked="checked"<?php endif;?> /> <?php echo Mage::helper('webdevlopers_productpageshipping')->__('No') ?>
</div>
</li>
<?php elseif ($this->useShoppingCart()):?>
<input id="estimate_cart_yes" type="hidden" name="estimate[cart]" value="1" />
<?php endif; ?>
</ul>
<script type="text/javascript">decorateList('shipping-estimation-form');</script>
<div class="actions">
<span class="please-wait f-left" id="shipping-estimate-loading-message" style="display:none;">
<?php echo Mage::helper('webdevlopers_productpageshipping')->__('') ?>
</span>
<div class="f-right">
<button type="button" id ="check1234" title="<?php echo Mage::helper('webdevlopers_productpageshipping')->getButton(); ?>"
onclick="estimateProductShipping()" class="button">
<span><span style ="font-size:11px; padding:5px;">
<?php echo Mage::helper('webdevlopers_productpageshipping')->__('CHECK') ?></span></span>
</button>
</div>
</div>
</div>
</div>
<!-- chnage
<a id="delivery-pincode-change" href="javascript:void(0)">change</a>
change end-->
<div id="shipping-estimate-results" style="display:none">
</div>
<script type="text/javascript">
( function($) {
$(document).ready(function(){
$('#estimate_postcode').keydown(function(e){
var items = $$(['.shipping-estimation-form input',
'.shipping-estimation-form select',
'#product_addtocart_form input',
'#product_addtocart_form select']);
var estimationUrl = '<?php echo $this->jsQuoteEscape($this->getEstimateUrl());?>';
var parameters = Form.serializeElements(items, true);
console.log("zipcode onkeypress worked");
if (!e) e = window.event;
var keyCode = e.keyCode || e.which;
if (keyCode == '13'){
//disable default enter action
e.preventDefault();
console.log("Enter button was pressed");
$('#shipping-estimate-loading-message').show();
$('#shipping-estimate-results').hide();
new Ajax.Updater('shipping-estimate-results', estimationUrl, {
parameters: parameters,
onComplete: function() {
console.log("ajax updater worked");
$('#shipping-estimate-loading-message').hide();
$('#shipping-estimate-results').show();
$('#unique_id').hide();
//$('unique_id').hide();
$('estimate_postcode').val()
}
});
};
});
});
} ) ( jQuery );
function estimateProductShipping()
{
var estimationUrl = '<?php echo $this->jsQuoteEscape($this->getEstimateUrl());?>';
var items = $$(['.shipping-estimation-form input',
'.shipping-estimation-form select',
'#product_addtocart_form input',
'#product_addtocart_form select']);
var validationResult = true;
// Check the valid input
if (!items.map(Validation.validate).all()) {
return;
}
var parameters = Form.serializeElements(items, true);
$('shipping-estimate-loading-message').show();
$('shipping-estimate-results').hide();
new Ajax.Updater('shipping-estimate-results', estimationUrl, {
parameters: parameters,
onComplete: function() {
console.log("ajax updater worked");
$('shipping-estimate-loading-message').hide();
$('shipping-estimate-results').show();
// $('#unique_id').hide();
$('unique_id').hide();
$('estimate_postcode').val()
}
});
}
function changeEstimate(){
$('unique_id').show();
$('shipping-estimate-results').hide();
}
/*
Event.observe('delivery-pincode-change', 'click', function(event){
$('unique_id').show();
$('shipping-estimate-results').hide();
$('delivery-html').hide();
});
*/
/*
$(document).ready(function(){
$('check1234').on('click', function(){
$('#unique_id').hide();
$('#shipping-estimate-results').show();
});
});
*/
//]]>
</script>
<!-- Raph -->
<?php if ($this->htmlEscape($this->getFieldValue('postcode'))): ?>
<script type="text/javascript">
Event.observe(window, 'load', function() {
estimateProductShipping();
});
</script>
<?php endif; ?>
<!-- Raph end-->
<?php endif;?>
Estimate.php
<?php
class WebDevlopers_ProductPageShipping_Model_Estimate
{
protected $_customer = null;
protected $_quote = null;
protected $_product = null;
protected $_result = array();
protected $_addressInfo = null;
public function setAddressInfo($info)
{
$this->_addressInfo = $info;
return $this;
}
public function getAddressInfo()
{
return $this->_addressInfo;
}
public function setProduct($product)
{
$this->_product = $product;
return $this;
}
public function getProduct()
{
return $this->_product;
}
public function getResult()
{
return $this->_result;
}
public function estimate()
{
$product = $this->getProduct();
$addToCartInfo = (array) $product->getAddToCartInfo();
$addressInfo = (array) $this->getAddressInfo();
if (!($product instanceof Mage_Catalog_Model_Product) || !$product->getId()) {
Mage::throwException(
Mage::helper('webdevlopers_productpageshipping')->__('Please specify a valid product')
);
}
if (!isset($addressInfo['country_id'])) {
Mage::throwException(
Mage::helper('webdevlopers_productpageshipping')->__('Please specify a country')
);
}
if (empty($addressInfo['cart'])) {
$this->resetQuote();
}
$shippingAddress = $this->getQuote()->getShippingAddress();
$shippingAddress->setCountryId($addressInfo['country_id']);
if (isset($addressInfo['region_id'])) {
$shippingAddress->setRegionId($addressInfo['region_id']);
}
if (isset($addressInfo['postcode'])) {
$shippingAddress->setPostcode($addressInfo['postcode']);
}
if (isset($addressInfo['region'])) {
$shippingAddress->setRegion($addressInfo['region']);
}
if (isset($addressInfo['city'])) {
$shippingAddress->setCity($addressInfo['city']);
}
$shippingAddress->setCollectShippingRates(true);
if (isset($addressInfo['coupon_code'])) {
$this->getQuote()->setCouponCode($addressInfo['coupon_code']);
}
$request = new Varien_Object($addToCartInfo);
if ($product->getStockItem()) {
$minimumQty = $product->getStockItem()->getMinSaleQty();
if($minimumQty > 0 && $request->getQty() < $minimumQty){
$request->setQty($minimumQty);
}
}
$result = $this->getQuote()->addProduct($product, $request);
if (is_string($result)) {
Mage::throwException($result);
}
Mage::dispatchEvent('checkout_cart_product_add_after',
array('quote_item' => $result, 'product' => $product));
$this->getQuote()->collectTotals();
$this->_result = $shippingAddress->getGroupedAllShippingRates();
return $this;
}
public function getQuote()
{
if ($this->_quote === null) {
$addressInfo = $this->getAddressInfo();
if (!empty($addressInfo['cart'])) {
$quote = Mage::getSingleton('checkout/session')->getQuote();
} else {
$quote = Mage::getModel('sales/quote');
}
$this->_quote = $quote;
}
return $this->_quote;
}
public function resetQuote()
{
$this->getQuote()->removeAllAddresses();
if ($this->getCustomer()) {
$this->getQuote()->setCustomer($this->getCustomer());
}
return $this;
}
public function getCustomer()
{
if ($this->_customer === null) {
$customerSession = Mage::getSingleton('customer/session');
if ($customerSession->isLoggedIn()) {
$this->_customer = $customerSession->getCustomer();
} else {
$this->_customer = false;
}
}
return $this->_customer;
}
}
ex: IN-stock Out- of -stock , zip : 110001
shipping is not Available
appears in the code