4

My code is as follows. Everything works fine except the filteration of new column which shows abandoned cart item names comma separately.

I have overridden the block Mage_Adminhtml_Block_Report_Shopcart_Abandoned_Grid.

protected function _prepareCollection()
    {
$collection = Mage::getResourceModel('reports/quote_collection');

        $filter = $this->getParam($this->getVarNameFilter(), array());
        if ($filter) {
            $filter = base64_decode($filter);
            parse_str(urldecode($filter), $data);
        }


        if (!empty($data)) {
            $collection->prepareForAbandonedReport($this->_storeIds, $data);
        } else {
            $collection->prepareForAbandonedReport($this->_storeIds);
        }

        $this->setCollection($collection);
        Mage_Adminhtml_Block_Report_Grid_Shopcart::_prepareCollection();
//------------------ my modifications---------------
// This was done to show item names comma separately in the abandoned cart grid as a new column.
foreach($collection as $col)
       {
           $itemcollection = $col->getItemsCollection();
           $products = array();
           foreach ($itemcollection as $item)
           {
               $products[] = $item->getName();
           }
             $productname = implode( " , ", $products);
             $col->setQuoteItemName($productname); 
       }
//------------------ my modifications---------------

   return $this;
}

protected function _prepareColumns()
    {
        parent::_prepareColumns();

    $this->addColumnAfter('quote_item_name', array(
            'header'    =>Mage::helper('reports_abandonedcart')->__('Item(s) Name'),
            'index'     =>'quote_item_name',
            'filter_index'=>'sales_flat_quote.quote_item_name', // What should be here 
            'sortable'  =>false
        ),'items_qty');


        return Mage_Adminhtml_Block_Report_Grid_Shopcart::_prepareColumns();
}
  • Can anybody make suggestion on this please? – Sukeshini Oct 4 '13 at 10:06
3

I am not 100% sure if this will work but what you could do is add a filter_condition_callback to the column.

'filter_condition_callback' => array($this, 'yourFilterCallback'),

Then write your function yourFilterCallback

protected function yourFilterCallback($collection, $column)
{
    $filterValue = $column->getFilter()->getValue();
    // Do what ever you need to the collection here
    return $this;
}
| improve this answer | |

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.