/**
  * @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;
 }
 /**
  * @param Customer $entity
  * @param int $rootId
  * @return array
  */
 protected function formatEntity(Customer $entity, $rootId)
 {
     return ['id' => $entity->getId(), 'parent' => $entity->getParent() && $entity->getParent()->getId() !== $rootId ? $entity->getParent()->getId() : '#', 'text' => $entity->getName(), 'state' => ['opened' => !$entity->getChildren()->isEmpty()]];
 }
 /**
  * @param Crawler $crawler
  * @param string $name
  * @param Customer $parent
  * @param CustomerGroup $group
  */
 protected function assertCustomerSave(Crawler $crawler, $name, Customer $parent, CustomerGroup $group, AbstractEnumValue $internalRating)
 {
     $form = $crawler->selectButton('Save and Close')->form(['orob2b_customer_type[name]' => $name, 'orob2b_customer_type[parent]' => $parent->getId(), 'orob2b_customer_type[group]' => $group->getId(), 'orob2b_customer_type[internal_rating]' => $internalRating->getId()]);
     $this->client->followRedirects(true);
     $crawler = $this->client->submit($form);
     $result = $this->client->getResponse();
     $this->assertHtmlResponseStatusCodeEquals($result, 200);
     $html = $crawler->html();
     $this->assertContains('Customer has been saved', $html);
     $this->assertViewPage($html, $name, $parent, $group, $internalRating);
 }
 /**
  * @Route("/info/{id}", name="orob2b_customer_info", requirements={"id"="\d+"})
  * @Template("OroB2BCustomerBundle:Customer/widget:info.html.twig")
  * @AclAncestor("orob2b_customer_view")
  *
  * @param Customer $customer
  * @return array
  */
 public function infoAction(Customer $customer)
 {
     return ['entity' => $customer, 'treeData' => $this->get('orob2b_customer.customer_tree_handler')->createTree($customer->getId())];
 }
 public function testCustomerView()
 {
     $this->client->request('GET', $this->getUrl('orob2b_customer_view', ['id' => $this->customer->getId()]));
     $result = $this->client->getResponse();
     $this->assertHtmlResponseStatusCodeEquals($result, 200);
 }