Shipping Methods – How to Add Shipping Method Options

shippingshipping-methods

I wrote a module with help of a this link and I don't know what to do if I want to show options for a shipping method,I mean I have one shipping(one carrier title) but different method names

is it related to creating other model? if so should I change my config.xml? or other file? I cvould not solve my problem I searched through internet a lot

            $method = Mage::getModel('shipping/rate_result_method');
            $method->setCarrier($this->_code);
            $method->setMethod($this->_code);
            $method->setCarrierTitle($this->getConfigData('title'));
            $method->setMethodTitle($this->getConfigData('name'));
            $method->setPrice($price);
            $method->setCost($price);
            $result->append($method);

Best Answer

Take a look at Mage_Shipping_Model_Rate_Request. If you have several methods, in the collectRates() method of the class that extends Mage_Shipping_Model_Carrier_Abstract you can create an array with method details. Then you can loop through the array:

public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
    if (!Mage::getStoreConfig('carriers/'.$carrierCode.'/enabled')) {
        return false;
    }

    $methods = array('method_one'=>array('price'=>some_val,'title'=>some_title,'cost'=>some_cost)...add more methods);


        $finalMethods = Mage::getModel('shipping/rate_result');

       foreach($methods as $item){

        $method = Mage::getModel('shipping/rate_result_method');
        $method->setCarrier($carrierCode);
        $method->setMethod($item['code']);
        $method->setCarrierTitle($carrierTitle);
        $method->setMethodTitle($item['title']);
        $method->setPrice($item['price']);
        $method->setCost($item['cost']);
        $finalMethods->append($method);
    }

    return $finalMethods;
}

Also take a look at this article: http://coding.smashingmagazine.com/2014/01/15/create-custom-shipping-methods-magento/ (there is a section called "Using Multiple Shipping Methods").