please visit link

you can see there is an option to check delivery is available or not by entering zip code.

enter image description here

you can see text "Selling Price + Rs 40 Delivery" in above image.

here 40 is shipping charge for that product

this value i am displaying by calling the attribute value code in view.phtml.

what i want is as we change the zip code, according to that shipping charge also should change and display the proper shipping charge.

This feature is working for Cart page using shipping.phtml code :

I am calling same phtml code in view.phtml as follows , but its not working:

echo $this->getLayout()->createBlock('checkout/cart_shipping')->setTemplate('checkout/cart/shipping1.phtml')->tohtml();  


<?php /** @var $this Mage_Checkout_Block_Cart_Shipping */ ?>
<div class="shipping">
    <h2><?php echo $this->__('') ?></h2>
    <div class="shipping-form">
       <form action="<?php echo $this->getUrl('checkout/cart/estimatePost') ?>" method="post" id="shipping-zip-form">

            <ul class="form-list">
            <div style="display:none">

                    <label for="country"><em>*</em><?php echo $this->__('Country') ?></label>
                <div class="input-box">
                        <?php echo Mage::getBlockSingleton('directory/data')->getCountryHtmlSelect($this->getEstimateCountryId()) ?>


            <?php //if($this->getStateActive()): ?>
                    <label for="region_id"<?php if ($this->isStateProvinceRequired()) echo ' class="required"' ?>><?php if ($this->isStateProvinceRequired()) echo '<em>*</em>' ?><?php echo $this->__('State/Province') ?></label>
                    <div class="input-box">
                        <select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" style="display:none;"<?php echo ($this->isStateProvinceRequired() ? ' class="validate-select"' : '') ?>>
                            <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
                       <script type="text/javascript">
                           $('region_id').setAttribute('defaultValue',  "<?php echo $this->getEstimateRegionId() ?>");
                       <input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getEstimateRegion()) ?>"  title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none;" />
            <?php //endif; ?>
            <?php if($this->getCityActive()): ?>
                    <label for="city"<?php if ($this->isCityRequired()) echo ' class="required"' ?>><?php if ($this->isCityRequired()) echo '<em>*</em>' ?><?php echo $this->__('City') ?></label>
                    <div class="input-box">
                        <input class="input-text<?php if ($this->isCityRequired()):?> required-entry<?php endif;?>" id="city" type="text" name="estimate_city" value="<?php echo $this->escapeHtml($this->getEstimateCity()) ?>" />
            <?php endif; ?>
                    <label for="postcode"<?php if ($this->isZipCodeRequired()) echo ' class="required"' ?>><?php if ($this->isZipCodeRequired()) echo '<em>*</em>' ?><?php echo $this->__('Check Delivery') ?></label>
                    <div class="input-box">
                        <input class="input-text validate-postcode<?php if ($this->isZipCodeRequired()):?> required-entry<?php endif;?>" type="text" id="postcode" name="estimate_postcode" value="<?php echo $this->escapeHtml($this->getEstimatePostcode()) ?>" />
            <div class="buttons-set">
                 <button type="button" title="<?php echo $this->__('Check') ?>" onclick="coShippingMethodForm.submit()" class="button">
                 <span><span><?php echo $this->__('Check') ?>


        <!-- Pras -->

    <?php if (($_shippingRateGroups = $this->getEstimateRates())): 

             echo Mage::getSingleton('core/session')->getMyShipMessage();

    endif; ?>   

    <!-- Pras end -->

        <script type="text/javascript">
            new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>);

        <?php if (($_shippingRateGroups = $this->getEstimateRates())): ?>
        <form id="co-shipping-method-form" action="<?php echo $this->getUrl('checkout/cart/estimateUpdatePost') ?>">
            <dl class="sp-methods">
                <?php foreach ($_shippingRateGroups as $code => $_rates): ?>
                    <dt><?php echo $this->escapeHtml($this->getCarrierName($code)) ?></dt>
                        <?php foreach ($_rates as $_rate): ?>
                            <li<?php if ($_rate->getErrorMessage()) echo ' class="error-msg"';?>>
                               <?php if ($_rate->getErrorMessage()): ?>
                                    <?php echo $this->escapeHtml($_rate->getErrorMessage()) ?>
                               <?php else: ?>
                                    <input name="estimate_method" type="radio" value="<?php echo $this->escapeHtml($_rate->getCode()) ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio" />
                                    <label for="s_method_<?php echo $_rate->getCode() ?>"><?php echo $this->escapeHtml($_rate->getMethodTitle()) ?>
                                    <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
                                    <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
                                    <?php echo $_excl; ?>
                                    <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
                                        (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
                                    <?php endif; ?>
                               <?php endif ?>
                        <?php endforeach; ?>
                <?php endforeach; ?>
            <div style="display:none;">
                <button type="submit" title="<?php echo $this->__('Update Total') ?>" class="button" name="do" 
                value="<?php echo $this->__('Update Total') ?>"><span><span><?php echo $this->__('Update Total') ?></span></span>
        <?php endif; ?>
        <script type="text/javascript">
            var coShippingMethodForm = new VarienForm('shipping-zip-form');
            var countriesWithOptionalZip = <?php echo $this->helper('directory')->getCountriesWithOptionalZip(true) ?>;

            coShippingMethodForm.submit = function () {
                var country = $F('country');
                var optionalZip = false;

                for (i=0; i < countriesWithOptionalZip.length; i++) {
                    if (countriesWithOptionalZip[i] == country) {
                        optionalZip = true;
                if (optionalZip) {
                else {
                return VarienForm.prototype.submit.bind(coShippingMethodForm)();



  • can you explain in details? – Abdul Mar 15 '16 at 7:46
  • once we enter the zip code on product view page, according to the shipping charges should display. – Baby in Magento Mar 15 '16 at 7:47
  • @Abdul we have separate shipping charges for each product. and even we calculated shipping charges based on distance. so once we enter the zip code according to that shipping charges should calculate. – Baby in Magento Mar 15 '16 at 9:09
  • can you check with table rate excel sheet? – Ajay Patel Mar 31 '16 at 12:48
  • just you need to add pin code, country, and your charges for available area. – Ajay Patel Mar 31 '16 at 12:48

It seems you want to calculate shipping cost for individual product and not on for whole cart total. In that case you follow below code to calculate shipping cost per product:

class Yanted_Export_Helper_Shipping extends Mage_Core_Helper_Abstract
    public function calculateShippingCosts($productId, $country,$zipcode, $storeId = 1)
        $product = Mage::getModel('catalog/product')->load($productId);
        $item = Mage::getModel('sales/quote_item')->setProduct($product)->setQty(1);
        $store = Mage::getModel('core/store')->load($storeId);

        $request = Mage::getModel('shipping/rate_request')

        $model = Mage::getModel('shipping/shipping')->collectRates($request);
        $costs = array();

        foreach($model->getResult()->getAllRates() as $rate) {
            $costs[$rate->getCarrier()] = array(
                'title' => trim($rate->getCarrierTitle()),
                'price' => $rate->getPrice()

        return $costs;

You need to create your action and should make an ajax call to get this rate dynamically.

$costs = Mage::helper('yanted_export/shipping')->calculateShippingCosts('123', 'US','10007', 2); 

Hope this can resolve your problem.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.