/** * resolve address records before setting headers, so we know how much addresses exist * * @param Sales_Model_CustomerFilter $filter * @param Sales_Controller_Customer $controller */ protected function _resolveAddresses($filter, $controller) { $customers = $controller->search($filter); $customerIds = $customers->id; $contactIds = array_unique(array_merge($customers->cpextern_id, $customers->cpintern_id)); unset($customers); $be = new Sales_Backend_Address(); $this->_specialFieldDefinitions = array(array('header' => 'Postal Address', 'identifier' => 'postal_address', 'type' => 'postal')); foreach (array('billing', 'delivery') as $type) { $maxAddresses = $be->getMaxAddressesByType($customerIds, $type); $header = $type == 'billing' ? 'Billing Address' : 'Delivery Address'; if ($maxAddresses > 0) { $i = 0; while ($i < $maxAddresses) { $this->_specialFieldDefinitions[] = array('header' => $header, 'identifier' => $type . '_address' . ($i > 0 ? $i + 1 : ''), 'type' => $type, 'index' => $i + 1); $i++; } } } $filter = new Sales_Model_AddressFilter(array()); $filter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'customer_id', 'operator' => 'in', 'value' => $customerIds))); $this->_addresses = $be->search($filter); $this->_contacts = Addressbook_Controller_Contact::getInstance()->getMultiple($contactIds); }