Advertisement
Guest User

Untitled

a guest
May 25th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. protected function _prepareCollection()
  2. {
  3. $collection = Mage::getResourceModel('customer/customer_collection')
  4. ->addNameToSelect()
  5. ->addAttributeToSelect('email')
  6. ->addAttributeToSelect('created_at')
  7. ->addAttributeToSelect('group_id')
  8. ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
  9. ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
  10. ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
  11. ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
  12. ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');
  13.  
  14. $collection->addAttributeToSelect('salesrep');
  15. parent::setCollection($collection);
  16.  
  17. // GET LAST ORDER DATE
  18. $sql ='SELECT MAX(o.created_at)'
  19. . ' FROM ' . Mage::getSingleton('core/resource')->getTableName('sales/order') . ' AS o'
  20. . ' WHERE o.customer_id = e.entity_id ';
  21. $expr = new Zend_Db_Expr('(' . $sql . ')');
  22.  
  23. $collection->getSelect()->from(null, array('last_order_date'=>$expr));
  24.  
  25. $this->setCollection($collection);
  26.  
  27. return parent::_prepareCollection();
  28. }
  29.  
  30. protected function _prepareColumns()
  31. {
  32. ...
  33.  
  34. $this->addColumn('last_order_date', array(
  35. 'header' => Mage::helper('customer')->__('Last Order Date'),
  36. 'type' => 'datetime',
  37. 'align' => 'left',
  38. 'index' => 'last_order_date',
  39. 'gmtoffset' => true
  40. ));
  41.  
  42. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement