1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Sales_Model_Resource_Billing_Agreement_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
36: {
37: 38: 39: 40: 41:
42: protected $_map = array('fields' => array(
43: 'customer_email' => 'ce.email',
44: 'customer_firstname' => 'firstname.value',
45: 'customer_lastname' => 'lastname.value',
46: 'agreement_created_at' => 'main_table.created_at',
47: 'agreement_updated_at' => 'main_table.updated_at',
48: ));
49:
50: 51: 52: 53:
54: protected function _construct()
55: {
56: $this->_init('sales/billing_agreement');
57: }
58:
59: 60: 61: 62: 63:
64: public function addCustomerDetails()
65: {
66: $select = $this->getSelect()->joinInner(
67: array('ce' => $this->getTable('customer/entity')),
68: 'ce.entity_id = main_table.customer_id',
69: array('customer_email' => 'email')
70: );
71:
72: $customer = Mage::getResourceSingleton('customer/customer');
73: $adapter = $this->getConnection();
74: $attr = $customer->getAttribute('firstname');
75: $joinExpr = 'firstname.entity_id = main_table.customer_id AND '
76: . $adapter->quoteInto('firstname.entity_type_id = ?', $customer->getTypeId()) . ' AND '
77: . $adapter->quoteInto('firstname.attribute_id = ?', $attr->getAttributeId());
78:
79: $select->joinLeft(
80: array('firstname' => $attr->getBackend()->getTable()),
81: $joinExpr,
82: array('customer_firstname' => 'value')
83: );
84:
85: $attr = $customer->getAttribute('lastname');
86: $joinExpr = 'lastname.entity_id = main_table.customer_id AND '
87: . $adapter->quoteInto('lastname.entity_type_id = ?', $customer->getTypeId()) . ' AND '
88: . $adapter->quoteInto('lastname.attribute_id = ?', $attr->getAttributeId());
89:
90: $select->joinLeft(
91: array('lastname' => $attr->getBackend()->getTable()),
92: $joinExpr,
93: array('customer_lastname' => 'value')
94: );
95: return $this;
96: }
97: }
98: