5

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);

1 Answer 1

6

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").

5
  • I don't have rate should I create a folder? I am totally a beginner at magento
    – Nickool
    Feb 7, 2014 at 20:16
  • Ok take a look at this article also : magentotricks.com/creating-a-customer-magento-shipping-method. You have a rate model: $method = Mage::getModel('shipping/**rate**_result_method'), this line gives you a rate model. Feb 7, 2014 at 20:19
  • yeah I found my rate folder thank you! great help!!!
    – Nickool
    Feb 7, 2014 at 20:21
  • You are welcome. Feb 7, 2014 at 20:22
  • This will indeed show multiple options, but will assign same carrierCode.. and it will create multiple radio options with same id. When selecting any shipping option will keep the first option in selection always May 21, 2016 at 11:11

Your Answer

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

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