×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: bejoy balan
Added: Nov 27, 2014 4:19 AM
Views: 14
http://ka.lpe.sh/2013/04/28/magento-join-eav-collection-with-flat-table/
  1. $coll = Mage::getModel('sales/order')->getCollection();
  2.  
  3. $fn = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'firstname');
  4. $ln = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'lastname');
  5.  
  6. $coll->getSelect()
  7.     ->join(array('ce1' => 'customer_entity_varchar'), 'ce1.entity_id=main_table.customer_id', array('firstname' => 'value'))
  8.     ->where('ce1.attribute_id='.$fn->getAttributeId())
  9.     ->join(array('ce2' => 'customer_entity_varchar'), 'ce2.entity_id=main_table.customer_id', array('lastname' => 'value'))
  10.     ->where('ce2.attribute_id='.$ln->getAttributeId())
  11.     ->columns(new Zend_Db_Expr("CONCAT(`ce1`.`value`, ' ',`ce2`.`value`) AS fullname"));
  12.  
  13. print_r($coll->getData());