0

I'm new to Magento, and need to add filter by website to Sales > Orders page. I try to override Mage_Adminhtml_Block_Sales_Order_Grid and add following code:

protected function _prepareColumns()
{
   $this->addColumn('website', array(
          'header' => Mage::helper('sales')->__('Website'),
          'index' => 'store_id',
          'type'  => 'options',
          'width' => '70px',
          'options'   => Mage::getModel('core/website')->getCollection()->toOptionHash(),
    ));
}

enter image description here

This is the result, only the English store have website associated. Can somebody help me?

1 Answer 1

0

I found solution:

protected function _filterWebsiteConditionCallback($collection, $column)
{
        if (!$value = $column->getFilter()->getValue()) {
            return $this;
        }

        $website = Mage::getModel('core/website')->load($value);

        foreach ($website->getGroups() as $group) {
            $stores = $group->getStores();
            foreach ($stores as $store) {
                $ids[] = $store->getId();
            }
        }

        $this->getCollection()->addFieldToFilter('main_table.store_id', $ids);

        return $this;
}


protected function _prepareColumns()
{
   $this->addColumn('website', array(
          'header' => Mage::helper('sales')->__('Website'),
          'index' => 'store_id',
          'type'  => 'options',
          'width' => '70px',
          'options'   => Mage::getModel('core/website')->getCollection()->toOptionHash(),
          'filter_condition_callback' => array($this, '_filterWebsiteConditionCallback'),
    ));
}

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.