Пример #1
0
 public function testAccountUserToAccountRelation()
 {
     $order = new Order();
     /** @var Account|\PHPUnit_Framework_MockObject_MockObject $account */
     $account = $this->getMock('OroB2B\\Bundle\\AccountBundle\\Entity\\Account');
     $account->expects($this->any())->method('getId')->will($this->returnValue(1));
     $accountUser = new AccountUser();
     $accountUser->setAccount($account);
     $this->assertEmpty($order->getAccount());
     $order->setAccountUser($accountUser);
     $this->assertSame($account, $order->getAccount());
 }
 /**
  * Get order related data
  *
  * @Route("/related-data", name="orob2b_order_related_data")
  * @Method({"GET"})
  * @AclAncestor("orob2b_order_update")
  *
  * @return JsonResponse
  */
 public function getRelatedDataAction()
 {
     $order = new Order();
     $accountUser = $this->getOrderHandler()->getAccountUser();
     $account = $this->getAccount($accountUser);
     $order->setAccount($account);
     $order->setAccountUser($accountUser);
     $accountPaymentTerm = null;
     if ($account) {
         $accountPaymentTerm = $this->getPaymentTermProvider()->getAccountPaymentTerm($account);
     }
     $accountGroupPaymentTerm = null;
     if ($account->getGroup()) {
         $accountGroupPaymentTerm = $this->getPaymentTermProvider()->getAccountGroupPaymentTerm($account->getGroup());
     }
     $orderForm = $this->createForm($this->getOrderFormTypeName(), $order);
     return new JsonResponse(['billingAddress' => $this->renderForm($orderForm->get(AddressType::TYPE_BILLING . 'Address')->createView()), 'shippingAddress' => $this->renderForm($orderForm->get(AddressType::TYPE_SHIPPING . 'Address')->createView()), 'accountPaymentTerm' => $accountPaymentTerm ? $accountPaymentTerm->getId() : null, 'accountGroupPaymentTerm' => $accountGroupPaymentTerm ? $accountGroupPaymentTerm->getId() : null]);
 }
Пример #3
0
 /**
  * @param Order $order
  * @param Request $request
  *
  * @return array|RedirectResponse
  */
 protected function update(Order $order, Request $request)
 {
     if (!$order->getAccountUser()) {
         $accountUser = $this->get('oro_security.security_facade')->getLoggedUser();
         if (!$accountUser instanceof AccountUser) {
             throw new \InvalidArgumentException('Only AccountUser can create an Order.');
         }
         $order->setAccountUser($accountUser);
     }
     if ($order->getAccount()) {
         $paymentTerm = $this->get('orob2b_payment.provider.payment_term')->getPaymentTerm($order->getAccount());
         if ($paymentTerm) {
             $order->setPaymentTerm($paymentTerm);
         }
     }
     //TODO: set correct owner in task BB-929
     if (!$order->getOwner()) {
         $user = $this->getDoctrine()->getManagerForClass('OroUserBundle:User')->getRepository('OroUserBundle:User')->findOneBy([]);
         $order->setOwner($user);
     }
     $form = $this->createForm(FrontendOrderType::NAME, $order);
     $handler = new OrderHandler($form, $request, $this->getDoctrine()->getManagerForClass(ClassUtils::getClass($order)), $this->get('orob2b_order.provider.subtotals'));
     return $this->get('oro_form.model.update_handler')->handleUpdate($order, $form, function (Order $order) {
         return ['route' => 'orob2b_order_frontend_update', 'parameters' => ['id' => $order->getId()]];
     }, function (Order $order) {
         return ['route' => 'orob2b_order_frontend_view', 'parameters' => ['id' => $order->getId()]];
     }, $this->get('translator')->trans('orob2b.order.controller.order.saved.message'), $handler, function (Order $order, FormInterface $form, Request $request) {
         return ['form' => $form->createView(), 'entity' => $order, 'isWidgetContext' => (bool) $request->get('_wid', false), 'isShippingAddressGranted' => $this->getOrderAddressSecurityProvider()->isAddressGranted($order, AddressType::TYPE_SHIPPING), 'isBillingAddressGranted' => $this->getOrderAddressSecurityProvider()->isAddressGranted($order, AddressType::TYPE_BILLING), 'tierPrices' => $this->getTierPrices($order), 'matchedPrices' => $this->getMatchedPrices($order)];
     });
 }
Пример #4
0
 /**
  * @param Order $order
  * @param Request $request
  *
  * @return array|RedirectResponse
  */
 protected function update(Order $order, Request $request)
 {
     if (in_array($request->getMethod(), ['POST', 'PUT'], true)) {
         $order->setAccount($this->getOrderHandler()->getAccount());
         $order->setAccountUser($this->getOrderHandler()->getAccountUser());
     }
     $form = $this->createForm(OrderType::NAME, $order);
     $handler = new OrderHandler($form, $request, $this->getDoctrine()->getManagerForClass(ClassUtils::getClass($order)), $this->get('orob2b_order.provider.subtotals'));
     return $this->get('oro_form.model.update_handler')->handleUpdate($order, $form, function (Order $order) {
         return ['route' => 'orob2b_order_update', 'parameters' => ['id' => $order->getId()]];
     }, function (Order $order) {
         return ['route' => 'orob2b_order_view', 'parameters' => ['id' => $order->getId()]];
     }, $this->get('translator')->trans('orob2b.order.controller.order.saved.message'), $handler, function (Order $order, FormInterface $form, Request $request) {
         return ['form' => $form->createView(), 'entity' => $order, 'isWidgetContext' => (bool) $request->get('_wid', false), 'isShippingAddressGranted' => $this->getOrderAddressSecurityProvider()->isAddressGranted($order, AddressType::TYPE_SHIPPING), 'isBillingAddressGranted' => $this->getOrderAddressSecurityProvider()->isAddressGranted($order, AddressType::TYPE_BILLING), 'tierPrices' => $this->getTierPrices($order), 'matchedPrices' => $this->getMatchedPrices($order)];
     });
 }