1

I'm working on a Magento setup for Subaccounts.

Each customer has the field "parent_customer". If the field is set, the account is a subaccount.

What I'm trying to do is add a simple filter to the Grid overview, so that I can show only parent accounts of only subaccounts.

in the overriding Grid.php file I've placed the following snippet into the _prepareColumns() method:

$this->addColumn('parent_customer', array(
        'header'    => Mage::helper('customer')->__('Subaccount'),
        'width'     => '10',
        'type'      => 'options',
        'options'   => array('0'=>'Nein', '1' => 'Ja'),
        'index'     => 'parent_customer',
        'filter_condition_callback' => array($this, '_callbackParentCustomer'),

    ));

And also added a new callback Method

protected function _callbackParentCustomer($collection, $column){
    $value = $column->getFilter()->getValue();
    if ($value === null) { //here check if filter is not null
        return $this;
    }

    /**
     * Here you can add filter to collection
     * or do other manipulations with collection.
     * As example you can check filter value and filter collection.
     */
    if ($value != 0) { 
        Mage::log('show subaccounts', null, 'product.log', true);
        $collection->addFieldToFilter('parent_customer', array('gt' => 0));
    }else{
        Mage::log('hide subaccounts', null, 'product.log', true);
        $collection->addFieldToFilter('parent_customer', array('eq' => ''));
    }

    return $this;
}

The Logs show, that both filters trigger. If I want to only show subaccounts ('gt' => 0) all works fine. Problem is, if I want to show all parent accounts I get an empty collection. Is there no way to filter for Items that don't have an attribute set?

leedch
  • 151
  • 7

0 Answers0