1

I created custom shipping methods using following link

http://www.smashingmagazine.com/2014/01/15/create-custom-shipping-methods-magento/

Now I want enable /disable option(multiselect) at system->configuration->shipping methods->custom carrier

(For example ups carrier->allowed methods multiselect field in system configuration->shipping methods).

In order to get I'm using following code in system.xml

<allowed_methods translate="label">
    <label>Allowed Methods</label>
    <frontend_type>multiselect</frontend_type>
    <source_model>smashingmagazine_mycarrier/source_methods</source_model>
    <sort_order>20</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>0</show_in_store>
    <can_be_empty>1</can_be_empty>
 </allowed_methods>

and I created Methods.php in proper place.

class SmashingMagazine_MyCarrier_Model_Source_Methods
{
    public function toOptionArray()
    {

        $arr = array();
//how to get created custom shipping methods here?

        return $arr;
    }
}
0

This post on Stackoverflow is exactly what you are looking for.

Copied from the answer:

public function toOptionArray($isMultiSelect = false)
{
    $methods = Mage::getSingleton('shipping/config')->getActiveCarriers();

    $options = array();

    foreach($methods as $_code => $_method)
    {
        if(!$_title = Mage::getStoreConfig("carriers/$_code/title"))
            $_title = $_code;

        $options[] = array('value' => $_code, 'label' => $_title . " ($_code)");
    }

    if($isMultiSelect)
    {
        array_unshift($options, array('value'=>'', 'label'=> Mage::helper('adminhtml')->__('--Please Select--')));
    }

    return $options;
}
0

In case you would like to disable (or enable) multishipping for your custom shipping method, you can use this code in your Model/Carrier.php

public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
    if (Mage::app()->getRequest()->getControllerName() === 'multishipping') {
        return false;
    }
    <...code...>
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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