Display Shipping Methods For A Product

This will display appropriate shipping methods on the product detail page

The Block Class

class Namespace_Module_Block_Catalog_Product_Delivery extends Mage_Core_Block_Template{

    protected $_product;

    public function _construct(){
       parent::_construct();
       $this->setTemplate('catalog/product/delivery.phtml');
    }

    public function setProductId($productId){
        $this->_product = Mage::getModel('catalog/product')->load($productId);
    }

    public function getDeliveryMethods(){
        $quote = Mage::getModel('sales/quote');
        $existingQuote = Mage::getSingleton('checkout/session')->getQuote();

        if($countryId = $existingQuote->getShippingAddress()->getCountryId()){
            $quote->getShippingAddress()->setCountryId($countryId);
        }else{
            $quote->getShippingAddress()->setCountryId(Mage::getStoreconfig('general/country/default'));
        }

        $quote->addProduct($this->_product);
        $quote->getShippingAddress()->collectTotals();
        $quote->getShippingAddress()->setCollectShippingRates(true);
        $quote->getShippingAddress()->collectShippingRates();
        $rates = $quote->getShippingAddress()->getShippingRatesCollection();

       return $rates;
    }

}
  • Load a new quote object and populate its address with the country of the existing quote or the default config country.
  • Add the product to the quote
  • return the rates

The Template

<?php
$_rates = $this->getDeliveryMethods();
?>

<p><?php echo $this->__("DELIVERY OPTIONS");?></p>
<?php if(count($_rates)):?>
    <ul class="product-rates">
    <?php foreach($_rates as $_rate):?>
        <li><?php echo $this->escapeHtml($_rate->getMethodTitle());?></li>
    <?php endforeach; ?>
    </ul>
<?php endif;?>