/** * @param Customer $customer * @param CustomerAddress $address * @return array * @throws BadRequestHttpException */ protected function update(Customer $customer, CustomerAddress $address) { $responseData = ['saved' => false, 'customer' => $customer]; if ($this->getRequest()->getMethod() == 'GET' && !$address->getId()) { if (!$customer->getAddresses()->count()) { $address->setPrimary(true); } } if ($address->getOwner() && $address->getOwner()->getId() != $customer->getId()) { throw new BadRequestHttpException('Address must belong to customer'); } elseif (!$address->getOwner()) { $customer->addAddress($address); } $form = $this->createForm(CustomerTypedAddressType::NAME, $address); $handler = new AddressHandler($form, $this->getRequest(), $this->getDoctrine()->getManagerForClass('OroB2BCustomerBundle:CustomerAddress')); if ($handler->process($address)) { $this->getDoctrine()->getManager()->flush(); $responseData['entity'] = $address; $responseData['saved'] = true; } $responseData['form'] = $form->createView(); return $responseData; }