/** * Lists customer's addresses * * @return \Symfony\Component\HttpFoundation\Response */ public function addressesAction() { $customer = $this->getCustomer(); $addresses = 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)); $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()); foreach ($custAddresses as $address) { $addresses[$address->getTypeCode()][] = $address; } } return $this->render('SonataCustomerBundle:Addresses:list.html.twig', array('addresses' => $addresses, 'customer' => $customer, 'breadcrumb_context' => 'customer_address')); }