public function addressesAction()
{
$customer = $this->getCustomer();
$typeCodes = BaseAddress::getTypesList();
// This allows to specify the display order
$addresses = array($typeCodes[AddressInterface::TYPE_DELIVERY] => array(), $typeCodes[AddressInterface::TYPE_BILLING] => array(), $typeCodes[AddressInterface::TYPE_CONTACT] => array());
if (null === $customer) {
// Customer not yet created, the user didn't order yet
$customer = $this->getCustomerManager()->create();
$customer->setUser($this->getUser());
$this->getCustomerManager()->save($customer);
} else {
$custAddresses = $this->getAddressManager()->findBy(array('customer' => $customer));
foreach ($custAddresses as $address) {
$addresses[$address->getTypeCode()][] = $address;
}
}
// Set redirection URL to be to the list of addresses
$this->get('session')->set('sonata_address_redirect', $this->generateUrl('sonata_customer_addresses'));
return $this->render('SonataCustomerBundle:Addresses:list.html.twig', array('addresses' => $addresses, 'customer' => $customer, 'breadcrumb_context' => 'customer_address'));
}