Inheritance: implements Sonata\Component\Customer\AddressInterface
 /**
  * Gets the HTML of an address
  *
  * @param \Twig_Environment $environment A Twig environment
  * @param mixed             $address     An instance of AddressInterface or array with keys: (id, firstname, lastname, address1, postcode, city, country_code and optionally name, address2, address3)
  * @param bool              $showName    Display address name?
  * @param bool              $showEdit    Display edit button?
  * @param string            $context     A context for edit link
  *
  * @throws InvalidParameterException
  *
  * @return string
  */
 public function renderAddress(\Twig_Environment $environment, $address, $showName = true, $showEdit = false, $context = null)
 {
     $requiredAddressKeys = array("firstname", "lastname", "address1", "postcode", "city", "country_code");
     if (!$address instanceof AddressInterface && (!is_array($address) || count(array_diff($requiredAddressKeys, array_keys($address))) !== 0)) {
         throw new InvalidParameterException(sprintf("sonata_address_render needs an AddressInterface instance or an array with keys (%s)", implode(", ", $requiredAddressKeys)));
     }
     if ($address instanceof AddressInterface) {
         $addressArray = array('id' => $showEdit ? $address->getId() : "", 'name' => $showName ? $address->getName() : "", 'address' => $address->getFullAddressHtml());
     } else {
         if ($showEdit && !array_key_exists("id", $address)) {
             throw new InvalidParameterException("sonata_address_render needs 'id' key to be set to render the edit button");
         }
         if ($showName && !array_key_exists('name', $address)) {
             $address["name"] = "";
             $showName = false;
         }
         $addressArray = array('id' => $showEdit ? $address['id'] : "", 'name' => $address['name'], 'address' => BaseAddress::formatAddress($address, "<br/>"));
     }
     return $environment->render('SonataCustomerBundle:Addresses:_address.html.twig', array('address' => $addressArray, 'showName' => $showName, 'showEdit' => $showEdit, 'context' => $context));
 }
Exemplo n.º 2
0
 /**
  * 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'));
 }
Exemplo n.º 3
0
 /**
  * Returns formatted billing address.
  *
  * @param string $sep
  *
  * @return string
  */
 public function getFullBilling($sep = ', ')
 {
     return BaseAddress::formatAddress($this->getBillingAsArray(), $sep);
 }