Magento 1.8 – Select Shipping Method on Cart Page

cartmagento-1.8shippingshipping-methods

I'm just wondering if it's possible to allow a customer to select a shipping method on the cart/basket page without entering country or postcode? I have added an image of a mockup to show what it is I'm looking to do. If anyone knows a tutorial or extension that would do this that would be great.

enter image description here

Best Answer

If you don't ship to different countries, or if you don't use the matrixrate extension, you can edit the estimate tax & shipping box to get this effect.

I've used this tutorial as a base:

http://www.arscommunity.com/wiki/magento/default-address-for-shipping-estimation

copy /app/code/core/Mage/Checkout/Model/Session.php 

to

/app/code/local/Mage/Checkout/Model/Session.php

and before:

$this->_quote = $quote;

add this

$sha = $quote->getShippingAddress();
if (!$sha->getCountry()) {
$country = Mage::getStoreConfig('shipping/origin/country_id');
$state = Mage::getStoreConfig('shipping/origin/region_id');
$postcode = Mage::getStoreConfig('shipping/origin/postcode');
$quote->getShippingAddress()
->setCountryId($country)
->setRegionId($state)
->setPostcode($postcode)
->setCollectShippingRates(true);
$this->resetCheckout();
$quote->save();
}

then copy

/app/design/frontend/base/default/checkout/cart/shipping.phtml

to

/app/design/frontend/default/YOURTEMPLATE/checkout/cart/shipping.phtml

and change it, I've changed it to:

  <div class="shipping">
<h2><?php echo $this->__('Estimate Shipping and Tax') ?></h2>
<div class="shipping-form">



    <?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 class="buttons-set">
            <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; ?>

</div>

Related Topic