Ejemplo n.º 1
0
 /**
  * Save user billing address
  *
  * @param Delivery $delivery
  */
 private function saveUserBillingAddress($delivery)
 {
     // get billing address
     /** @var Address $billingAddress */
     $billingAddress = $this->manager->getRepository('EcommerceBundle:Address')->findOneBy(array('actor' => $this->securityContext->getToken()->getUser(), 'forBilling' => true));
     // build new billing address when it does not exist
     if (is_null($billingAddress)) {
         $billingAddress = new Address();
         $billingAddress->setForBilling(true);
         $billingAddress->setActor($this->securityContext->getToken()->getUser());
     }
     $billingAddress->setContactPerson($delivery->getContactPerson());
     $billingAddress->setDni($delivery->getDni());
     $billingAddress->setAddressInfo($delivery->getAddressInfo());
     $billingAddress->setPhone($delivery->getPhone());
     $billingAddress->setPhone2($delivery->getPhone2());
     $billingAddress->setPreferredSchedule($delivery->getPreferredSchedule());
     $country = $this->manager->getRepository('CoreBundle:Country')->find('es');
     $billingAddress->setCountry($country);
     $this->manager->persist($billingAddress);
     $this->manager->flush();
 }