/**
  * @param AccountUser $accountUser
  * @param AccountUserAddress $address
  * @return array
  * @throws BadRequestHttpException
  */
 protected function update(AccountUser $accountUser, AccountUserAddress $address)
 {
     $responseData = ['saved' => false, 'entity' => $accountUser];
     if ($this->getRequest()->getMethod() === 'GET' && !$address->getId()) {
         $address->setFirstName($accountUser->getFirstName());
         $address->setLastName($accountUser->getLastName());
         if (!$accountUser->getAddresses()->count()) {
             $address->setPrimary(true);
         }
     }
     if (!$address->getFrontendOwner()) {
         $accountUser->addAddress($address);
     } elseif ($address->getFrontendOwner()->getId() !== $accountUser->getId()) {
         throw new BadRequestHttpException('Address must belong to AccountUser');
     }
     $form = $this->createForm(AccountUserTypedAddressType::NAME, $address);
     $manager = $this->getDoctrine()->getManagerForClass($this->container->getParameter('orob2b_account.entity.account_user_address.class'));
     $handler = new AddressHandler($form, $this->getRequest(), $manager);
     if ($handler->process($address)) {
         $this->getDoctrine()->getManager()->flush();
         $responseData['entity'] = $address;
         $responseData['saved'] = true;
     }
     $responseData['form'] = $form->createView();
     $responseData['routes'] = ['create' => 'orob2b_account_account_user_address_create', 'update' => 'orob2b_account_account_user_address_update'];
     return $responseData;
 }
 /**
  * @depends testUpdate
  * @param $id
  */
 public function testView($id)
 {
     $this->client->request('GET', $this->getUrl('orob2b_account_frontend_account_user_role_view', ['id' => $id]));
     $this->assertResponseStatusCodeEquals($this->client->getResponse(), 200);
     $response = $this->requestFrontendGrid('frontend-account-account-users-grid-view', ['frontend-account-account-users-grid-view[role]' => $id, 'frontend-account-account-users-grid-view[_filter][email][value]' => OroLoadAccountUserData::AUTH_USER]);
     $result = $this->getJsonResponseContent($response, 200);
     $this->assertCount(1, $result['data']);
     $result = reset($result['data']);
     $this->assertEquals($this->currentUser->getId(), $result['id']);
     $this->assertEquals($this->currentUser->getFirstName(), $result['firstName']);
     $this->assertEquals($this->currentUser->getLastName(), $result['lastName']);
     $this->assertEquals($this->currentUser->getEmail(), $result['email']);
 }
 /**
  * "Success" form handler
  *
  * @param ShoppingList $entity
  * @return bool
  */
 protected function onSuccess(ShoppingList $entity)
 {
     $rfpRequest = new RFPRequest();
     $rfpRequest->setFirstName($this->user->getFirstName())->setLastName($this->user->getLastName())->setEmail($this->user->getEmail())->setPhone('')->setRole('')->setBody('')->setCompany($this->user->getOrganization() ? $this->user->getOrganization()->getName() : '')->setAccountUser($this->user)->setAccount($this->user->getAccount())->setStatus($this->requestStatus);
     foreach ($entity->getLineItems() as $shoppingListLineItem) {
         $requestProduct = new RequestProduct();
         $requestProduct->setProduct($shoppingListLineItem->getProduct());
         $requestProductItem = new RequestProductItem();
         $requestProductItem->setQuantity($shoppingListLineItem->getQuantity())->setProductUnit($shoppingListLineItem->getUnit());
         $requestProduct->addRequestProductItem($requestProductItem);
         $rfpRequest->addRequestProduct($requestProduct);
     }
     try {
         $this->manager->persist($rfpRequest);
         $this->manager->flush();
         $this->rfpRequest = $rfpRequest;
     } catch (DBALException $e) {
         $this->exception = $e;
         return false;
     }
     return true;
 }