/** * Build a delivery object for the current actor * * @param Transaction $transaction * * @return Delivery */ public function getDelivery(Transaction $transaction = null) { if ($this->session->has('delivery-id')) { $delivery = $this->manager->getRepository('EcommerceBundle:Delivery')->find($this->session->get('delivery-id')); return $delivery; } $delivery = new Delivery(); /** @var Address $billingAddress */ $billingAddress = $this->manager->getRepository('EcommerceBundle:Address')->findOneBy(array('actor' => $this->securityContext->getToken()->getUser(), 'forBilling' => true)); if (false === is_null($billingAddress)) { $delivery->setFullName($this->securityContext->getToken()->getUser()->getFullName()); $delivery->setContactPerson($billingAddress->getContactPerson()); $delivery->setDni($billingAddress->getDni()); $delivery->setAddressInfo($billingAddress->getAddressInfo()); $delivery->setPhone($billingAddress->getPhone()); $delivery->setPhone2($billingAddress->getPhone2()); $delivery->setPreferredSchedule($billingAddress->getPreferredSchedule()); } $country = $this->manager->getRepository('CoreBundle:Country')->find('es'); $delivery->setCountry($country); if (false === is_null($transaction)) { $delivery->setTransaction($transaction); } return $delivery; }