0

To make my admin Sales/Orders grid better I added column to the grid: enter image description here

and as on the picture above it shows order delivery method but ... how to create "delivery method" dropdown list to make it easier to use? So far I tried to add a class:

public function getCarrierList()
{
    $shippingMethods = Mage::getSingleton('shipping/config')->getActiveCarriers();  
    $methods = array();
    foreach($shippingMethods as $method)
    {
            $methods[$method['value']] = $methods[$method['label']];
    }
    return $methods;
}

and added to the column definition:

    $this->addColumn('shipping_method', array(
        'header' => Mage::helper('sales')->__('Shipping Method'),
        'index' => 'shipping_description',
        'type'=> 'options',
        'filter_index' => 'shipping_method',
        'options' => $this->getCarrierList(),
    ));

but then my column stays empty and drop-down is also empty. Of course I can live without it but if I can have a list instead of a typing method name .. would be nice.

2 Answers 2

2

Please try the below code to show shipping method in sales grid.

protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());

        $collection->getSelect()->join( array('order'=> 'sales_flat_order'), 'order.entity_id = main_table.entity_id', array('order.shipping_method'));

        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

In _prepareColumns function,

$this->addColumn('shipping_method', array(
        'header' => Mage::helper('sales')->__('Shipping Method'),
        'index' => 'shipping_method',
        'type'=> 'options',
        'options' => $this->getCarrierList(),
    ));

The carrierList function,

 public function getCarrierList()
    {
        $shippingMethods = Mage::getSingleton('shipping/config')->getActiveCarriers(); 
        $methods = array();
        foreach($shippingMethods as $_code => $_method)
        {
             $_title = Mage::getStoreConfig("carriers/$_code/title");
           if(!empty($_title)) {
             $_title = $_code; 
             $methods[$_title ."_$_code"]=  $_title ."_$_code";
            }
        }
        return $methods;
    }
2

Try with the below carrierList function.

public function getCarrierList()
{
    $shippingMethods = Mage::getSingleton('shipping/config')->getActiveCarriers();  
    $methods = array();
    foreach($shippingMethods as $_code => $_method)
    {
         $_title = Mage::getStoreConfig("carriers/$_code/title");
        if(!empty($_title)) {
         $_title = $_code; 
         $methods[$_code]=  $_title;
        }
    }
    return $methods;
}
1
  • Better, your code gave me 3 methods (in database I have 100% at least 8 but it is a little step forward) ;) and still if I add 'type' => 'options', to the column definition it stops displaying delivery method from order.
    – Rob D. A.
    Commented Jul 4, 2017 at 13:58

Your Answer

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

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