0

i need to add 'company' attribute of customer to invoice grid. below is the code i change and its showing correct query results in phpmyadmin, but somehow it only shows 2 as a Total records on Invoice grid.

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->getSelect()->joinInner(array('order_address' => Mage::getSingleton('core/resource')->getTableName('sales_flat_order_address')),'order_address.parent_id = main_table.order_id',array('company'))->group('parent_id')->order('entity_id', 'desc');

    $this->setCollection($collection);
    return parent::_prepareCollection();
}

and query is

SELECT `main_table`.*, `order_address`.`company` FROM `sales_flat_invoice_grid` AS `main_table` INNER JOIN `sales_flat_order_address` AS `order_address` ON order_address.parent_id = main_table.order_id GROUP BY `parent_id`

if i change the number of records to 200 per page , it shows all that records , but there is some issue in paging and total records.

It always shows 1 page and 'Total 2 records found'. So i can not move to next page.

Anye help please.

Thanks

magento2new
  • 517
  • 1
  • 10
  • 38

2 Answers2

0

Please check the following links. You may get an idea.

Adding to Grid Selection for grid.php file

http://www.magentocommerce.com/boards/viewthread/197590/

http://www.widgetsandburritos.com/adding-fields-order-invoice-grid-magento/

Community
  • 1
  • 1
Sarath Tomy
  • 504
  • 4
  • 12
0

for any one having the issue with broken admin grid pager, here is the solution.

Copy Db.php file from magento / lib / Varien / Data / Collection / Db.php Paste it to your local directory so the resultant folder structure would look like this: magento / app / code / local / Varien / Data / Collection / Db.php

public function getSelectCountSql()
{
    $this->_renderFilters();
    $countSelect = clone $this->getSelect();
    $countSelect->reset(Zend_Db_Select::ORDER);
    $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
    $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
    $countSelect->reset(Zend_Db_Select::COLUMNS);
    if(count($this->getSelect()->getPart(Zend_Db_Select::GROUP)) > 0) {
        $countSelect->reset(Zend_Db_Select::GROUP);
        $countSelect->distinct(true);
        $group = $this->getSelect()->getPart(Zend_Db_Select::GROUP);
        $countSelect->columns("COUNT(DISTINCT ".implode(", ", $group).")");
    } else {
        $countSelect->columns('COUNT(*)');
    }
    return $countSelect;
}
magento2new
  • 517
  • 1
  • 10
  • 38