0

in cart page , we implemented a feature of finding shipping charges using this file : app/design/frontend/default/theme/template/checkout/cart/shipping.phtml

I need the same feature in cart page....

cart page file : app/design/frontend/default/theme/template/checkout/cart/item/default.phtml file.

so i created static block with identifier : "delivery" , than inserted following code :

{{block type="core/template" template="checkout/cart/shipping.phtml"}}

than in default.phtml file, i used this code :

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('delivery')->toHtml();  ?> 

but its not working for me. shipping.phtml code

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email protected] so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academiac Free License (AFL 3.0)
 */
?>
<?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">

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

                </li>
            </div>

            <?php //if($this->getStateActive()): ?>
            <!--
                <li>
                    <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>
                        </select>
                       <script type="text/javascript">
                       //<![CDATA[
                           $('region_id').setAttribute('defaultValue',  "<?php echo $this->getEstimateRegionId() ?>");
                       //]]>
                       </script>
                       <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;" />
                   </div>
                </li>
            -->
            <?php //endif; ?>
            <?php if($this->getCityActive()): ?>
                <li>
                    <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()) ?>" />
                    </div>
                </li>
            <?php endif; ?>
                <li>
                    <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>
                </li>
            </ul>
            <div class="buttons-set">
                <button type="button" title="<?php echo $this->__('Check') ?>" onclick="coShippingMethodForm.submit()" class="button"><span><span><?php echo $this->__('Check') ?></span></span></button>
            </div>





        </form>



        <!-- Prashant -->
     <td>


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

       if(Mage::getSingleton('core/session')->getMyShipMessage()){
             echo Mage::getSingleton('core/session')->getMyShipMessage();
             Mage::getSingleton('core/session')->unsMyShipMessage();
        }

    endif; ?>



    </td>

    <!-- Prashant end -->


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

        <?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>
                    <dd>
                        <ul>
                        <?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; ?>
                                    </label>
                               <?php endif ?>
                            </li>
                        <?php endforeach; ?>
                        </ul>
                    </dd>
                <?php endforeach; ?>
            </dl>
            <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>
                </button>
            </div>
        </form>
        <?php endif; ?>
        <script type="text/javascript">
        //<![CDATA[
            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) {
                    $('postcode').removeClassName('required-entry');
                }
                else {
                    $('postcode').addClassName('required-entry');
                }
                return VarienForm.prototype.submit.bind(coShippingMethodForm)();
            }





        //]]>
        </script>
    </div>
</div>

1 Answer 1

1

Try {{block type='core/template' area='frontend' template='checkout/cart/shipping.phtml'}}

And if it's not working, maybe your shipping phtml needs any information about the shipping? Maybe you need to assign it in the block statement like {{block type='core/template' area='frontend' template='checkout/cart/shipping.phtml' shipping=$shipping}} or {{block type='core/template' area='frontend' template='checkout/cart/shipping.phtml' order=$order}} to retrieve informations for shipping via order.

Also remind to always clear all caches including redis, varnish and so on if given.

5
  • sorry , I tried all 3 solutions, but it did't worked for me. magento cache was disabled. we are using shared hosting , so we cant clear redis or varnish cache. Mar 8, 2016 at 12:24
  • Is your shipping.phtml the same like in app/design/frontend/base?
    – Michael
    Mar 8, 2016 at 15:54
  • not exactly same , i did some customizations Mar 8, 2016 at 16:13
  • it worked for me for UI part : {{block type="checkout/cart_shipping" template="checkout/cart/shipping.phtml"}} Mar 10, 2016 at 6:56
  • visit link and click on "Buy Now" button you can see 2 "check" butttons, one inside table, type"560043" and check its not giving shipping charges. but when we use the "check" button present below, than it will work. Mar 10, 2016 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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