1

I have modified the Abandoned cart grid collection so it can have some additional columns. But the issue is all the records are showing in one page. I tried with setPageSize(). But it didn't work out. How can I solve this issue?

Any suggestions will appreciated.

EDIT: 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);
        }

//------------------ 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---------------

    $this->setCollection($collection);

        return Mage_Adminhtml_Block_Report_Grid_Shopcart::_prepareCollection();
}

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'=>'table_quote_items.name',
            'sortable'  =>false
        ),'items_qty');


        return Mage_Adminhtml_Block_Report_Grid_Shopcart::_prepareColumns();
}
  • can you add the code u used for adding columns? – Shathish Oct 4 '13 at 6:17
  • @Shathish : See my EDIT – Sukeshini Oct 4 '13 at 6:24
  • I think foreach loop is causes this issue. Any suggestions please? – Sukeshini Oct 4 '13 at 7:00
3

This is your problem: foreach($collection as $col). You are iterating the collection before the pagination can set the limit on the select. This will cause the collection to be loaded, and any modification to it after that has no effect.
You can try to call this before your custom code:

$this->setCollection($collection);
Mage_Adminhtml_Block_Report_Grid_Shopcart::_prepareCollection();

Then comes your code and at the end add return $this. This will also load the collection but only after the pagination has added the limit on the sql.

  • Still I have another issue with the filter-index. Can you tell me what should I put as filter-index for this column? Do I need to use a Renderer class for this? – Sukeshini Oct 4 '13 at 7:52
  • @Su123. You got me here. I have no idea. Maybe you should ask an other question and focus on the filter_index part. – Marius Oct 4 '13 at 7:55
  • Thanks for your quick response. I'll put it as a new question. – Sukeshini Oct 4 '13 at 7:56

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.