1

I am trying to add a weight column to my magento order grid (I want the total weight of the order)

I have this part

_prepareColumns $this->addColumn('weight', array( 'header' => Mage::helper('sales')->__('Weight'), 'index' => 'weight', 'filter_index' => 'sfo.weight', 'width' => '50px', )); 

The column is shown, but no data is displayed

I think I need to add something in front of _prepareCollection();

Does anyone know the correct code for this?

below is the collection part i have already

protected function _getCollectionClass() { return 'sales/order_grid_collection'; } protected function _prepareCollection() { $collection = Mage::getResourceModel($this->_getCollectionClass()); $table = Mage::getSingleton('core/resource')->getTableName('sales_flat_shipment_grid'); //$collection->getSelect()->from('', "((select max(t.created_at) from `$table` as t where t.order_id=main_table.entity_id)) as shipped_date"); $collection ->getSelect() ->joinLeft(array('t'=>$table), 'main_table.entity_id = t.order_id',array('shipped_date'=>'created_at')) ->group('main_table.entity_id');; //file_put_contents(basename(__FILE__).".txt",__LINE__.":sql: ".$collection->getSelect()."\r\n",FILE_APPEND); $this->setCollection($collection); $collection->getSelect()->joinLeft(array('shipping'=>'sales_flat_order_address'), 'main_table.entity_id = shipping.parent_id AND shipping.address_type="shipping"',array('shipping.postcode AS sp')); return parent::_prepareCollection(); } 
4
  • can you please confirm your collection got correct weight. or sfo.weight is correct filed Commented Jun 12, 2017 at 7:40
  • can you please share your collection Commented Jun 12, 2017 at 8:21
  • Hi, I don't have one, as when I enter anything, I get an error on the page. Commented Jun 12, 2017 at 8:49
  • protected function _prepareCollection() $collection->getSelect()->joinLeft(array('shipping'=>'sales_flat_order_address'), 'main_table.entity_id = shipping.parent_id AND shipping.address_type="shipping"',array('shipping.postcode AS sp')); return parent::_prepareCollection(); } Commented Jun 12, 2017 at 8:52

1 Answer 1

0

The problem is you are calling wrong table.

there is no field in the name of weight in sales_flat_shipment_grid. it is in sales_flat_order_address. also please call 'filter_index' => 'sfo.weight' to 'filter_index' => 'weight'

protected function _prepareCollection() { $collection = Mage::getResourceModel($this->_getCollectionClass()); $table = Mage::getSingleton('core/resource')->getTableName('sales_flat_order_item'); $collection ->getSelect() ->joinLeft(array('t'=>$table), 'main_table.entity_id = t.order_id',array('shipped_date'=>'created_at')) ->group('main_table.entity_id'); $this->setCollection($collection); $collection->getSelect()->joinLeft(array('shipping'=>'sales_flat_order_address'), 'main_table.entity_id = shipping.parent_id AND shipping.address_type="shipping"',array('shipping.postcode AS sp')); return parent::_prepareCollection(); } 
6
  • Please check it let me know Commented Jun 12, 2017 at 9:39
  • if it is work please Accept the answer. :) Commented Jun 12, 2017 at 10:22
  • this is what I have, but its not working, can you give me the whole string? Commented Jun 12, 2017 at 12:50
  • $collection->getSelect()->join('sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id' AND'filter_index' => 'sfo.weight' to 'filter_index' => 'weight'array('email'=> 'email', 'weight'=> 'weight' )); $collection->addFieldToFilter('sales_flat_order_address.address_type', array('eq' => 'billing')); Commented Jun 12, 2017 at 12:50
  • Can you give detail in question? Commented Jun 12, 2017 at 13:16

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.