Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

A Custom Like Filter for DropDownLists in the Admin Order Grid
 
methodagile
Jr. Member
 
Total Posts:  28
Joined:  2009-01-21
 

I have added a column to the Order grid in the Admin site.  Now, I would like it to be a dropdownlist that filters values based on a LIKE query.

For example, a custom column exists called “Shipping Method”.  This column displays values prepended with “fedex_” or “usps_”.  Rather than a dropdownlist with every shipping method.  We’d like to have only two options being “fedex” and “usps”, so that we can filter to the shipping carrier.

We have copied

\app\code\core\Mage\Adminhtml\Block\Sales\Order\Grid.php

to

\app\code\local\Mage\Adminhtml\Block\Sales\Order\

and changed this

$this->addColumn('shipping_method', array(
            
'header'=> Mage::helper('sales')->__('Shipping Method'),
            
'width' => '80px',
            
'type'  => 'text',
            
'index' => 'shipping_method',
        ));

to

$this->addColumn('shipping_method', array(
            
'header' => Mage::helper('sales')->__('Shipping Method'),
            
'index' => 'shipping_method',
            
'type'  => 'options',
            
'width' => '80px',
            
'options' => array("fedex" => "fedex""usps" => "usps"),
        ));

I have also copied

app\code\core\Mage\Adminhtml\Block\Widget\Grid\Column\Filter\Select.php

to

app\code\local\Mage\Adminhtml\Block\Widget\Grid\Column\Filter\Select.php

and changed

public function getCondition()
    
{
        
if (is_null($this->getValue())) {
            
return null;
        
}
        
print($this->getValue());
        return array(
'eq' => $this->getValue());
    
}

to

public function getCondition()
    
{
        
if (is_null($this->getValue())) {
            
return null;
        
}
        
print($this->getValue());
        return array(
'like' => '%'.$this->getValue().'%');
    
}

The result is a dropdownlist with “fedex” and “usps” as options.  However, now every order has an empty cell for this value.  Therefore, I can’t filter on this column.  It looks like the absence of values is the issue.

 
Magento Community Magento Community
Magento Community
Magento Community
 
methodagile
Jr. Member
 
Total Posts:  28
Joined:  2009-01-21
 

So it turns out that if one of the actual options is included in the array at Grid.php, then the cells of those orders are filled appropriately.  It looks like the values in the grid are somehow linked to the values populated in the filter dropdownlist.

Is there a way to disassociate the strict filter from the column’s values?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top